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);
113 m_scalar = - 0.5 * (e1*x + e2*y + e3*z);
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;
320 double y = ep0.
m_vec * s;