vector_angle.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00013 #ifndef vector_angle_h
00014 #define vector_angle_h
00015
00016 #include <cml/mathlib/checking.h>
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 namespace cml {
00028
00030 template< class VecT_1, class VecT_2, class VecT_3 >
00031 typename detail::DotPromote<
00032 typename detail::CrossPromote<VecT_1,VecT_2>::promoted_vector, VecT_3
00033 >::promoted_scalar
00034 signed_angle(const VecT_1& v1, const VecT_2& v2, const VecT_3& reference)
00035 {
00036 typedef typename detail::CrossPromote<VecT_1,VecT_2>::promoted_vector
00037 vector_type;
00038 typedef typename detail::DotPromote<vector_type,VecT_3>::promoted_scalar
00039 value_type;
00040
00041 vector_type c = cross(v1,v2);
00042 value_type angle = std::atan2(double(length(c)),double(dot(v1,v2)));
00043 return dot(c,reference) < value_type(0) ? -angle : angle;
00044 }
00045
00047 template< class VecT_1, class VecT_2 >
00048 typename detail::DotPromote< VecT_1, VecT_2 >::promoted_scalar
00049 unsigned_angle(const VecT_1& v1, const VecT_2& v2) {
00050 return std::atan2(double(length(cross(v1,v2))),double(dot(v1,v2)));
00051 }
00052
00054 template< class VecT_1, class VecT_2 >
00055 typename detail::DotPromote< VecT_1, VecT_2 >::promoted_scalar
00056 signed_angle_2D(const VecT_1& v1, const VecT_2& v2) {
00057 return std::atan2(double(perp_dot(v1,v2)),double(dot(v1,v2)));
00058 }
00059
00061 template< class VecT_1, class VecT_2 >
00062 typename detail::DotPromote< VecT_1, VecT_2 >::promoted_scalar
00063 unsigned_angle_2D(const VecT_1& v1, const VecT_2& v2) {
00064 return std::fabs(signed_angle_2D(v1,v2));
00065 }
00066
00067 }
00068
00069 #endif