public void testMatrix()
throws NotARotationMatrixException {
try {
new Rotation(new double[][] {
{ 0.0, 1.0, 0.0 },
{ 1.0, 0.0, 0.0 }
}, 1.0e-7);
} catch (NotARotationMatrixException nrme) {
// expected behavior
} catch (Exception e) {
fail("wrong exception caught: " + e.getMessage());
}
try {
new Rotation(new double[][] {
{ 0.445888, 0.797184, -0.407040 },
{ 0.821760, -0.184320, 0.539200 },
{ -0.354816, 0.574912, 0.737280 }
}, 1.0e-7);
} catch (NotARotationMatrixException nrme) {
// expected behavior
} catch (Exception e) {
fail("wrong exception caught: " + e.getMessage());
}
try {
new Rotation(new double[][] {
{ 0.4, 0.8, -0.4 },
{ -0.4, 0.6, 0.7 },
{ 0.8, -0.2, 0.5 }
}, 1.0e-15);
} catch (NotARotationMatrixException nrme) {
// expected behavior
} catch (Exception e) {
fail("wrong exception caught: " + e.getMessage());
}
checkRotation(new Rotation(new double[][] {
{ 0.445888, 0.797184, -0.407040 },
{ -0.354816, 0.574912, 0.737280 },
{ 0.821760, -0.184320, 0.539200 }
}, 1.0e-10),
0.8, 0.288, 0.384, 0.36);
checkRotation(new Rotation(new double[][] {
{ 0.539200, 0.737280, 0.407040 },
{ 0.184320, -0.574912, 0.797184 },
{ 0.821760, -0.354816, -0.445888 }
}, 1.0e-10),
0.36, 0.8, 0.288, 0.384);
checkRotation(new Rotation(new double[][] {
{ -0.445888, 0.797184, -0.407040 },
{ 0.354816, 0.574912, 0.737280 },
{ 0.821760, 0.184320, -0.539200 }
}, 1.0e-10),
0.384, 0.36, 0.8, 0.288);
checkRotation(new Rotation(new double[][] {
{ -0.539200, 0.737280, 0.407040 },
{ -0.184320, -0.574912, 0.797184 },
{ 0.821760, 0.354816, 0.445888 }
}, 1.0e-10),
0.288, 0.384, 0.36, 0.8);
double[][] m1 = { { 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
{ 1.0, 0.0, 0.0 } };
Rotation r = new Rotation(m1, 1.0e-7);
checkVector(r.applyTo(Vector3D.PLUS_I), Vector3D.PLUS_K);
checkVector(r.applyTo(Vector3D.PLUS_J), Vector3D.PLUS_I);
checkVector(r.applyTo(Vector3D.PLUS_K), Vector3D.PLUS_J);
double[][] m2 = { { 0.83203, -0.55012, -0.07139 },
{ 0.48293, 0.78164, -0.39474 },
{ 0.27296, 0.29396, 0.91602 } };
r = new Rotation(m2, 1.0e-12);
double[][] m3 = r.getMatrix();
double d00 = m2[0][0] - m3[0][0];
double d01 = m2[0][1] - m3[0][1];
double d02 = m2[0][2] - m3[0][2];
double d10 = m2[1][0] - m3[1][0];
double d11 = m2[1][1] - m3[1][1];
double d12 = m2[1][2] - m3[1][2];
double d20 = m2[2][0] - m3[2][0];
double d21 = m2[2][1] - m3[2][1];
double d22 = m2[2][2] - m3[2][2];
assertTrue(Math.abs(d00) < 6.0e-6);
assertTrue(Math.abs(d01) < 6.0e-6);
assertTrue(Math.abs(d02) < 6.0e-6);
assertTrue(Math.abs(d10) < 6.0e-6);
assertTrue(Math.abs(d11) < 6.0e-6);
assertTrue(Math.abs(d12) < 6.0e-6);
assertTrue(Math.abs(d20) < 6.0e-6);
assertTrue(Math.abs(d21) < 6.0e-6);
assertTrue(Math.abs(d22) < 6.0e-6);
assertTrue(Math.abs(d00) > 4.0e-7);
assertTrue(Math.abs(d01) > 4.0e-7);
assertTrue(Math.abs(d02) > 4.0e-7);
assertTrue(Math.abs(d10) > 4.0e-7);
assertTrue(Math.abs(d11) > 4.0e-7);
assertTrue(Math.abs(d12) > 4.0e-7);
assertTrue(Math.abs(d20) > 4.0e-7);
assertTrue(Math.abs(d21) > 4.0e-7);
assertTrue(Math.abs(d22) > 4.0e-7);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
double m3tm3 = m3[i][0] * m3[j][0]
+ m3[i][1] * m3[j][1]
+ m3[i][2] * m3[j][2];
if (i == j) {
assertTrue(Math.abs(m3tm3 - 1.0) < 1.0e-10);
} else {
assertTrue(Math.abs(m3tm3) < 1.0e-10);
}
}
}
checkVector(r.applyTo(Vector3D.PLUS_I),
new Vector3D(m3[0][0], m3[1][0], m3[2][0]));
checkVector(r.applyTo(Vector3D.PLUS_J),
new Vector3D(m3[0][1], m3[1][1], m3[2][1]));
checkVector(r.applyTo(Vector3D.PLUS_K),
new Vector3D(m3[0][2], m3[1][2], m3[2][2]));
double[][] m4 = { { 1.0, 0.0, 0.0 },
{ 0.0, -1.0, 0.0 },
{ 0.0, 0.0, -1.0 } };
r = new Rotation(m4, 1.0e-7);
checkAngle(r.getAngle(), Math.PI);
try {
double[][] m5 = { { 0.0, 0.0, 1.0 },
{ 0.0, 1.0, 0.0 },
{ 1.0, 0.0, 0.0 } };
r = new Rotation(m5, 1.0e-7);
fail("got " + r + ", should have caught an exception");
} catch (NotARotationMatrixException e) {
// expected
} catch (Exception e) {
fail("wrong exception caught");