126 double cr = Math.cos(roll * 0.5);
127 double sr = Math.sin(roll * 0.5);
129 double cp = Math.cos(pitch * 0.5);
130 double sp = Math.sin(pitch * 0.5);
132 double cy = Math.cos(yaw * 0.5);
133 double sy = Math.sin(yaw * 0.5);
137 cr * cp * cy + sr * sp * sy,
138 sr * cp * cy - cr * sp * sy,
139 cr * sp * cy + sr * cp * sy,
140 cr * cp * sy - sr * sp * cy);
222 final var R = rotationMatrix;
226 if (R.times(R.transpose()).minus(
Matrix.
eye(
Nat.
N3())).normF() > 1e-9) {
227 var msg =
"Rotation matrix isn't orthogonal\n\nR =\n" + R.getStorage().toString() +
'\n';
229 throw new IllegalArgumentException(msg);
231 if (Math.abs(R.det() - 1.0) > 1e-9) {
233 "Rotation matrix is orthogonal but not special orthogonal\n\nR =\n"
234 + R.getStorage().toString()
237 throw new IllegalArgumentException(msg);
242 double trace = R.
get(0, 0) + R.get(1, 1) + R.get(2, 2);
249 double s = 0.5 / Math.sqrt(trace + 1.0);
251 x = (R.get(2, 1) - R.get(1, 2)) * s;
252 y = (R.get(0, 2) - R.get(2, 0)) * s;
253 z = (R.get(1, 0) - R.get(0, 1)) * s;
255 if (R.get(0, 0) > R.get(1, 1) && R.get(0, 0) > R.get(2, 2)) {
256 double s = 2.0 * Math.sqrt(1.0 + R.get(0, 0) - R.get(1, 1) - R.get(2, 2));
257 w = (R.get(2, 1) - R.get(1, 2)) / s;
259 y = (R.get(0, 1) + R.get(1, 0)) / s;
260 z = (R.get(0, 2) + R.get(2, 0)) / s;
261 }
else if (R.get(1, 1) > R.get(2, 2)) {
262 double s = 2.0 * Math.sqrt(1.0 + R.get(1, 1) - R.get(0, 0) - R.get(2, 2));
263 w = (R.get(0, 2) - R.get(2, 0)) / s;
264 x = (R.get(0, 1) + R.get(1, 0)) / s;
266 z = (R.get(1, 2) + R.get(2, 1)) / s;
268 double s = 2.0 * Math.sqrt(1.0 + R.get(2, 2) - R.get(0, 0) - R.get(1, 1));
269 w = (R.get(1, 0) - R.get(0, 1)) / s;
270 x = (R.get(0, 2) + R.get(2, 0)) / s;
271 y = (R.get(1, 2) + R.get(2, 1)) / s;
289 double dot = initial.
dot(last);
290 double normProduct = initial.
norm() * last.
norm();
291 double dotNorm = dot / normProduct;
293 if (dotNorm > 1.0 - 1E-9) {
297 }
else if (dotNorm < -1.0 + 1E-9) {
302 double x = Math.abs(initial.
get(0, 0));
303 double y = Math.abs(initial.
get(1, 0));
304 double z = Math.abs(initial.
get(2, 0));
328 double axisNorm = axis.norm();
331 0.0, axis.get(0, 0) / axisNorm, axis.get(1, 0) / axisNorm, axis.get(2, 0) / axisNorm);
337 new Quaternion(normProduct + dot, axis.get(0, 0), axis.get(1, 0), axis.get(2, 0))