2#include "tools/SO3Util.h"
14 Vector3d::cross(a, b, sO3FromTwoVecN);
15 if (sO3FromTwoVecN.length() == 0.0)
17 double dot = Vector3d::dot(a, b);
24 Vector3d::ortho(a, sO3FromTwoVecRotationAxis);
25 rotationPiAboutAxis(sO3FromTwoVecRotationAxis, result);
30 sO3FromTwoVecA.set(a);
31 sO3FromTwoVecB.set(b);
33 sO3FromTwoVecN.normalize();
34 sO3FromTwoVecA.normalize();
35 sO3FromTwoVecB.normalize();
38 r1.setColumn(0, sO3FromTwoVecA);
39 r1.setColumn(1, sO3FromTwoVecN);
42 Vector3d::cross(sO3FromTwoVecN, sO3FromTwoVecA, temp31);
43 r1.setColumn(2, temp31);
46 r2.setColumn(0, sO3FromTwoVecB);
47 r2.setColumn(1, sO3FromTwoVecN);
48 Vector3d::cross(sO3FromTwoVecN, sO3FromTwoVecB, temp31);
49 r2.setColumn(2, temp31);
52 Matrix3x3d::mult(r2, r1, result);
60 rotationPiAboutAxisTemp.set(v);
61 rotationPiAboutAxisTemp.scale(3.141592653589793 / rotationPiAboutAxisTemp.length());
62 double invTheta = 0.3183098861837907;
64 double kB = 0.2026423672846756;
65 rodriguesSo3Exp(rotationPiAboutAxisTemp, kA, kB, result);
74 double thetaSq = Vector3d::dot(w, w);
75 double theta = sqrt(thetaSq);
77 if (thetaSq < 1.0E-08)
79 kA = 1.0 - 0.16666667163372 * thetaSq;
84 if (thetaSq < 1.0E-06)
86 kB = 0.5 - 0.0416666679084301 * thetaSq;
87 kA = 1.0 - thetaSq * 0.16666667163372 * (1.0 - 0.16666667163372 * thetaSq);
91 double invTheta = 1.0 / theta;
92 kA = sin(theta) * invTheta;
93 kB = (1.0 - cos(theta)) * (invTheta * invTheta);
96 rodriguesSo3Exp(w, kA, kB, result);
105 double cosAngle = (so3.get(0, 0) + so3.get(1, 1) + so3.get(2, 2) - 1.0) * 0.5;
107 result.set((so3.get(2, 1) - so3.get(1, 2)) / 2.0, (so3.get(0, 2) - so3.get(2, 0)) / 2.0, (so3.get(1, 0) - so3.get(0, 1)) / 2.0);
109 double sinAngleAbs = result.length();
110 if (cosAngle > 0.7071067811865476)
112 if (sinAngleAbs > 0.0)
113 result.scale(asin(sinAngleAbs) / sinAngleAbs);
115 else if (cosAngle > -0.7071067811865476)
117 double angle = acos(cosAngle);
118 result.scale(angle / sinAngleAbs);
122 double angle = 3.141592653589793 - asin(sinAngleAbs);
123 double d0 = so3.get(0, 0) - cosAngle;
124 double d1 = so3.get(1, 1) - cosAngle;
125 double d2 = so3.get(2, 2) - cosAngle;
128 if ((d0 * d0 > d1 * d1) && (d0 * d0 > d2 * d2))
130 r2.set(d0, (so3.get(1, 0) + so3.get(0, 1)) / 2.0, (so3.get(0, 2) + so3.get(2, 0)) / 2.0);
132 else if (d1 * d1 > d2 * d2)
134 r2.set((so3.get(1, 0) + so3.get(0, 1)) / 2.0, d1, (so3.get(2, 1) + so3.get(1, 2)) / 2.0);
138 r2.set((so3.get(0, 2) + so3.get(2, 0)) / 2.0, (so3.get(2, 1) + so3.get(1, 2)) / 2.0, d2);
141 if (Vector3d::dot(r2, result) < 0.0)
158 double wx2 = w.x * w.x;
159 double wy2 = w.y * w.y;
160 double wz2 = w.z * w.z;
162 result.set(0, 0, 1.0 - kB * (wy2 + wz2));
163 result.set(1, 1, 1.0 - kB * (wx2 + wz2));
164 result.set(2, 2, 1.0 - kB * (wx2 + wy2));
168 b = kB * (w.x * w.y);
169 result.set(0, 1, b - a);
170 result.set(1, 0, b + a);
173 b = kB * (w.x * w.z);
174 result.set(0, 2, b + a);
175 result.set(2, 0, b - a);
178 b = kB * (w.y * w.z);
179 result.set(1, 2, b - a);
180 result.set(2, 1, b + a);
185 result.set(i, 0, 0.0);
186 result.set((i + 1) % 3, 0, -pos.get((i + 2) % 3, 0));
187 result.set((i + 2) % 3, 0, pos.get((i + 1) % 3, 0));