23 double cth = ep1 * ep2;
29 if(cth > 1.0) cth = 1.0;
30 double th = acos(cth);
38 add(ep_temp1, ep_temp2);
42 ep_temp1 = sin(th-th2) * ep1;
43 ep_temp2 = sin(th2) * ep2;
44 add(ep_temp1, ep_temp2);
61 tr = mat(0,0) + mat(1,1) + mat(2,2);
67 m_vec(0) = (mat(2,1) - mat(1,2)) * s;
68 m_vec(1) = (mat(0,2) - mat(2,0)) * s;
69 m_vec(2) = (mat(1,0) - mat(0,1)) * s;
74 if(mat(1,1) > mat(0,0)) i = 1;
75 if(mat(2,2) > mat(i,i)) i = 2;
79 s = sqrt((mat(0,0) - (mat(1,1) + mat(2,2))) + 1);
82 m_vec(1) = (mat(0,1) + mat(1,0)) * s;
83 m_vec(2) = (mat(2,0) + mat(0,2)) * s;
84 m_scalar = (mat(2,1) - mat(1,2)) * s;
87 s = sqrt((mat(1,1) - (mat(2,2) + mat(0,0))) + 1);
90 m_vec(2) = (mat(1,2) + mat(2,1)) * s;
91 m_vec(0) = (mat(0,1) + mat(1,0)) * s;
92 m_scalar = (mat(0,2) - mat(2,0)) * s;
95 s = sqrt((mat(2,2) - (mat(0,0) + mat(1,1))) + 1);
98 m_vec(0) = (mat(2,0) + mat(0,2)) * s;
99 m_vec(1) = (mat(1,2) + mat(2,1)) * s;
100 m_scalar = (mat(1,0) - mat(0,1)) * s;
111 double e0 = ep(3), e1 = ep(0), e2 = ep(1), e3 = ep(2);
112 double x = vel(0),
y = vel(1), z = vel(2);
114 m_vec(0) = 0.5 * (e0*x - e3*
y + e2*z);
115 m_vec(1) = 0.5 * (e3*x + e0*
y - e1*z);
116 m_vec(2) = 0.5 * (- e2*x + e1*
y + e0*z);
124 #if 1 // based on Baraff's code 126 tr = mat(0,0) + mat(1,1) + mat(2,2);
132 ret(0) = (mat(2,1) - mat(1,2)) * s;
133 ret(1) = (mat(0,2) - mat(2,0)) * s;
134 ret(2) = (mat(1,0) - mat(0,1)) * s;
139 if(mat(1,1) > mat(0,0)) i = 1;
140 if(mat(2,2) > mat(i,i)) i = 2;
144 s = sqrt((mat(0,0) - (mat(1,1) + mat(2,2))) + 1);
147 ret(1) = (mat(0,1) + mat(1,0)) * s;
148 ret(2) = (mat(2,0) + mat(0,2)) * s;
149 ret(3) = (mat(2,1) - mat(1,2)) * s;
152 s = sqrt((mat(1,1) - (mat(2,2) + mat(0,0))) + 1);
155 ret(2) = (mat(1,2) + mat(2,1)) * s;
156 ret(0) = (mat(0,1) + mat(1,0)) * s;
157 ret(3) = (mat(0,2) - mat(2,0)) * s;
160 s = sqrt((mat(2,2) - (mat(0,0) + mat(1,1))) + 1);
163 ret(0) = (mat(2,0) + mat(0,2)) * s;
164 ret(1) = (mat(1,2) + mat(2,1)) * s;
165 ret(3) = (mat(1,0) - mat(0,1)) * s;
170 double e0, e1, e2, e3,
temp, ee, e0e1, e0e2, e0e3;
171 ee = (mat(0,0) + mat(1,1) + mat(2,2) + 1) / 4;
177 temp = ee - ((mat(1,1) + mat(2,2)) / 2);
178 if(temp < 0) temp = 0;
180 e0e1 = mat(2,1) - mat(1,2);
181 if(e0e1 < 0) e1 *= -1.0;
185 temp = ee - ((mat(2,2) + mat(0,0)) / 2);
186 if(temp < 0) temp = 0;
188 e0e2 = mat(0,2) - mat(2,0);
189 if(e0e2 < 0) e2 *= -1.0;
193 temp = ee - ((mat(0,0) + mat(1,1)) / 2);
194 if(temp < 0) temp = 0;
196 e0e3 = mat(1,0) - mat(0,1);
197 if(e0e3 < 0) e3 *= -1.0;
203 ret(2) = (mat(1,2) + mat(2,1)) / temp;
209 ret(1) = (mat(0,1) + mat(1,0)) / temp;
210 ret(2) = (mat(0,2) + mat(2,0)) / temp;
216 ret(0) = (mat(2,1) - mat(1,2)) / temp;
217 ret(1) = (mat(0,2) - mat(2,0)) / temp;
218 ret(2) = (mat(1,0) - mat(0,1)) / temp;
229 double ex = epara(0), ey = epara(1), ez = epara(2), e = epara(3);
230 double ee = e * e, exx = ex * ex, eyy = ey * ey, ezz = ez * ez;
231 double exy = ex * ey, eyz = ey * ez, ezx = ez * ex;
232 double eex = e * ex, eey = e * ey, eez = e * ez;
233 ret(0,0) = exx - eyy - ezz + ee;
234 ret(1,1) = - exx + eyy - ezz + ee;
235 ret(2,2) = - exx - eyy + ezz + ee;
236 ret(0,1) = 2.0 * (exy - eez);
237 ret(1,0) = 2.0 * (exy + eez);
238 ret(0,2) = 2.0 * (ezx + eey);
239 ret(2,0) = 2.0 * (ezx - eey);
240 ret(1,2) = 2.0 * (eyz - eex);
241 ret(2,1) = 2.0 * (eyz + eex);
272 fMat33 mat(epara(3), -epara(2), epara(1), epara(2), epara(3), -epara(0), -epara(1), epara(0), epara(3));
273 ret(3) = - epara.
Vec() * vel * 0.5;
274 ret.
Axis() = mat * vel * 0.5;
282 fMat33 mat(epara(3), epara(2), -epara(1), -epara(2), epara(3), epara(0), epara(1), -epara(0), epara(3));
283 ret = (- edot(3)*epara.
Vec() + mat*edot.
Vec()) * 2;
291 fMat33 mat1(e(3), e(2), -e(1), -e(2), e(3), e(0), e(1), -e(0), e(3));
292 fMat33 mat2(de(3), de(2), -de(1), -de(2), de(3), de(0), de(1), -de(0), de(3));
293 ret = 2 * (-de(3)*de.Vec() + mat2*de.Vec() - dde(3)*e.
Vec() + mat1*dde.
Vec());
299 double len = sqrt((*
this) * (*
this));
300 if(len >
eps) (*this) /= len;
friend fEulerPara operator*(double, const fEulerPara &)
Multiply with a scalar.
void set(const fMat33 &mat)
Copies a matrix.
void add(const fVec4 &vec1, const fVec4 &vec2)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
friend fMat33 ep2mat(const fEulerPara &)
Convert an Euler parameter representation to matrix.
friend fVec3 epdot2angvel(const fEulerPara &epara, const fEulerPara &edot)
Convert Euler parameter velocity to angular velocity.
Euler parameter representation of orientation.
friend fVec3 & Axis(fEulerPara &ep)
Access the vector part (a*sin(theta/2))
void set(double *v)
Set element values from array or three values.
void set(const fVec3 &v, double s)
Set the elements.
void unit()
Convert to unit vector.
friend fVec3 epddot2angacc(const fEulerPara &e, const fEulerPara &de, const fEulerPara &dde)
Convert Euler parameter acceleration to angular acceleration.
friend double & Ang(fEulerPara &ep)
Access the scalar part (cos(theta/2))
friend fEulerPara mat2ep(const fMat33 &)
Convert an orientation matrix to Euler parameters.
double rotation(const fEulerPara &ep0, const fVec3 &s)
returns the rotation angle that makes the orientation closest to ep0 by rotating around axis s ...
fEulerPara operator=(const fEulerPara &)
Assignment operator.
void angvel2epdot(const fEulerPara &_ep, const fVec3 &_omega)
Convert angular velocity to Euler parameter veclotiy.
friend fEulerPara operator-(const fEulerPara &)
Convert to the negative vector (represents the same orientation).
void interpolate(const fEulerPara &ep1, const fEulerPara &ep2, double t)
SLERP interpolation: interpolates ep1 and ep2 into t:(1-t)