123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include "quat_to_axis_angle.h"
- #include "EPS.h"
- #include "PI.h"
- #include <cmath>
- #include <cstdio>
- template <typename Q_type>
- IGL_INLINE void igl::quat_to_axis_angle(
- const Q_type *q,
- Q_type *axis,
- Q_type & angle)
- {
- if( fabs(q[3])>(1.0 + igl::EPS<Q_type>()) )
- {
-
- angle = 0;
- }
- else
- {
- double a;
- if( q[3]>=1.0f )
- a = 0;
- else if( q[3]<=-1.0f )
- a = PI;
- else if( fabs(q[0]*q[0]+q[1]*q[1]+q[2]*q[2]+q[3]*q[3])<igl::EPS_SQ<Q_type>())
- {
- a = 0;
- }else
- {
- a = acos(q[3]);
- if( a*angle<0 )
- a = -a;
- double f = 1.0f / sin(a);
- axis[0] = q[0] * f;
- axis[1] = q[1] * f;
- axis[2] = q[2] * f;
- }
- angle = 2.0*a;
- }
-
-
-
-
-
- if( fabs(angle)<igl::EPS<Q_type>()&& fabs(axis[0]*axis[0]+axis[1]*axis[1]+axis[2]*axis[2])<igl::EPS_SQ<Q_type>())
- {
- axis[0] = 1.0e-7;
- }
- }
- template <typename Q_type>
- IGL_INLINE void igl::quat_to_axis_angle_deg(
- const Q_type *q,
- Q_type *axis,
- Q_type & angle)
- {
- igl::quat_to_axis_angle(q,axis,angle);
- angle = angle*(180.0/PI);
- }
- #ifdef IGL_STATIC_LIBRARY
- template void igl::quat_to_axis_angle<float>(float const*, float*, float&);
- template void igl::quat_to_axis_angle_deg<float>(float const*, float*, float&);
- #endif
|