30 #define _USE_MATH_DEFINES // For MSVC 90 double tmp1 = fabs(data[0]);
91 double tmp2 = fabs(data[1]);
93 if (tmp1 == 0.0 && tmp2 == 0.0)
97 return tmp1*
sqrt(1+
sqr(data[1]/data[0]));
99 return tmp2*
sqrt(1+
sqr(data[0]/data[1]));
106 double v = this->
Norm();
122 tmp1 = fabs(data[0]);
123 tmp2 = fabs(data[1]);
131 return tmp1*
sqrt(1+
sqr(data[1]/data[0])+
sqr(data[2]/data[0]));
133 return tmp2*
sqrt(1+
sqr(data[0]/data[2])+
sqr(data[1]/data[2]));
138 return tmp2*
sqrt(1+
sqr(data[0]/data[1])+
sqr(data[2]/data[1]));
140 return tmp1*
sqrt(1+
sqr(data[0]/data[2])+
sqr(data[1]/data[2]));
149 double v = this->
Norm();
193 double x2, y2, z2, w2;
194 x2 = x*x; y2 = y*y; z2 = z*z; w2 = w*w;
195 return Rotation(w2+x2-y2-z2, 2*x*y-2*w*z, 2*x*z+2*w*y,
196 2*x*y+2*w*z, w2-x2+y2-z2, 2*y*z-2*w*x,
197 2*x*z-2*w*y, 2*y*z+2*w*x, w2-x2-y2+z2);
207 double trace = (*this)(0,0) + (*
this)(1,1) + (*
this)(2,2);
209 if( trace > epsilon ){
210 double s = 0.5 /
sqrt(trace + 1.0);
212 x = ( (*this)(2,1) - (*
this)(1,2) ) * s;
213 y = ( (*this)(0,2) - (*
this)(2,0) ) * s;
214 z = ( (*this)(1,0) - (*
this)(0,1) ) * s;
216 if ( (*
this)(0,0) > (*
this)(1,1) && (*
this)(0,0) > (*
this)(2,2) ){
217 double s = 2.0 *
sqrt( 1.0 + (*
this)(0,0) - (*
this)(1,1) - (*
this)(2,2));
218 w = ((*this)(2,1) - (*
this)(1,2) ) / s;
220 y = ((*this)(0,1) + (*
this)(1,0) ) / s;
221 z = ((*this)(0,2) + (*
this)(2,0) ) / s;
222 }
else if ((*
this)(1,1) > (*
this)(2,2)) {
223 double s = 2.0 *
sqrt( 1.0 + (*
this)(1,1) - (*
this)(0,0) - (*
this)(2,2));
224 w = ((*this)(0,2) - (*
this)(2,0) ) / s;
225 x = ((*this)(0,1) + (*
this)(1,0) ) / s;
227 z = ((*this)(1,2) + (*
this)(2,1) ) / s;
229 double s = 2.0 *
sqrt( 1.0 + (*
this)(2,2) - (*
this)(0,0) - (*
this)(1,1) );
230 w = ((*this)(1,0) - (*
this)(0,1) ) / s;
231 x = ((*this)(0,2) + (*
this)(2,0) ) / s;
232 y = ((*this)(1,2) + (*
this)(2,1) ) / s;
240 double ca1,cb1,cc1,sa1,sb1,sc1;
241 ca1 =
cos(yaw); sa1 =
sin(yaw);
242 cb1 =
cos(pitch);sb1 =
sin(pitch);
243 cc1 =
cos(roll);sc1 =
sin(roll);
244 return Rotation(ca1*cb1,ca1*sb1*sc1 - sa1*cc1,ca1*sb1*cc1 + sa1*sc1,
245 sa1*cb1,sa1*sb1*sc1 + ca1*cc1,sa1*sb1*cc1 - ca1*sc1,
246 -sb1,cb1*sc1,cb1*cc1);
254 if ( fabs(pitch) > (M_PI/2.0-epsilon) ) {
255 yaw =
atan2( -data[1], data[4]);
258 roll =
atan2(data[7], data[8]);
259 yaw =
atan2(data[3], data[0]);
264 double sa,ca,sb,cb,sg,cg;
265 sa =
sin(Alfa);ca =
cos(Alfa);
266 sb =
sin(Beta);cb =
cos(Beta);
267 sg =
sin(Gamma);cg =
cos(Gamma);
268 return Rotation( ca*cb*cg-sa*sg, -ca*cb*sg-sa*cg, ca*sb,
269 sa*cb*cg+ca*sg, -sa*cb*sg+ca*cg, sa*sb,
278 if (fabs(data[8]) > 1-epsilon ) {
282 alpha=
atan2(data[3],data[0]);
285 alpha=
atan2(-data[3],-data[0]);
288 alpha=
atan2(data[5], data[2]);
290 gamma=
atan2(data[7], -data[6]);
310 double ct =
cos(angle);
311 double st =
sin(angle);
313 double m_vt_0=vt*rotvec(0);
314 double m_vt_1=vt*rotvec(1);
315 double m_vt_2=vt*rotvec(2);
316 double m_st_0=rotvec(0)*st;
317 double m_st_1=rotvec(1)*st;
318 double m_st_2=rotvec(2)*st;
319 double m_vt_0_1=m_vt_0*rotvec(1);
320 double m_vt_0_2=m_vt_0*rotvec(2);
321 double m_vt_1_2=m_vt_1*rotvec(2);
323 ct + m_vt_0*rotvec(0),
327 ct + m_vt_1*rotvec(1),
331 ct + m_vt_2*rotvec(2)
362 double epsilon2 = eps*10;
367 if ((
std::abs(data[1] - data[3]) < epsilon)
368 && (
std::abs(data[2] - data[6])< epsilon)
369 && (
std::abs(data[5] - data[7]) < epsilon))
374 if ((
std::abs(data[1] + data[3]) < epsilon2)
375 && (
std::abs(data[2] + data[6]) < epsilon2)
376 && (
std::abs(data[5] + data[7]) < epsilon2)
377 && (
std::abs(data[0] + data[4] + data[8]-3) < epsilon2))
388 double xx = (data[0] + 1) / 2;
389 double yy = (data[4] + 1) / 2;
390 double zz = (data[8] + 1) / 2;
391 double xy = (data[1] + data[3]) / 4;
392 double xz = (data[2] + data[6]) / 4;
393 double yz = (data[5] + data[7]) / 4;
395 if ((xx > yy) && (xx > zz))
422 double f = (data[0] + data[4] + data[8] - 1) / 2;
425 x = (data[7] - data[5]);
426 y = (data[2] - data[6]);
427 z = (data[3] - data[1]);
represents rotations in 3 dimensional space.
double Normalize(double eps=epsilon)
friend bool operator==(const Frame &a, const Frame &b)
The literal equality operator==(), also identical.
double GetRotAngle(Vector &axis, double eps=epsilon) const
INLINE S Norm(const Rall1d< T, V, S > &value)
double Normalize(double eps=epsilon)
const double PI
the value of pi
static Rotation Quaternion(double x, double y, double z, double w)
INLINE Rall1d< T, V, S > sqr(const Rall1d< T, V, S > &arg)
Rotation M
Orientation of the Frame.
void GetQuaternion(double &x, double &y, double &z, double &w) const
static Frame DH_Craig1989(double a, double alpha, double d, double theta)
A concrete implementation of a 3 dimensional vector class.
static Rotation RPY(double roll, double pitch, double yaw)
static Frame DH(double a, double alpha, double d, double theta)
double epsilon
default precision while comparing with Equal(..,..) functions. Initialized at 0.0000001.
Vector p
origine of the Frame
double min(double a, double b)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
void Make4x4(double *d)
Reads data from an double array.
void GetEulerZYZ(double &alpha, double &beta, double &gamma) const
void GetRPY(double &roll, double &pitch, double &yaw) const
INLINE Rall1d< T, V, S > acos(const Rall1d< T, V, S > &x)
Vector operator*(const Vector &arg) const
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
static Rotation EulerZYZ(double Alfa, double Beta, double Gamma)
represents a frame transformation in 3D space (rotation + translation)
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
friend bool Equal(const Frame &a, const Frame &b, double eps)
static Rotation Rot(const Vector &rotvec, double angle)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
static Rotation Rot2(const Vector &rotvec, double angle)
Along an arbitrary axes. rotvec should be normalized.
double max(double a, double b)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)