Quaternion implements Serializable { public Quaternion getInverse() { final double squareNorm = q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3; if (squareNorm < Precision.SAFE_MIN) { throw new ZeroException(LocalizedFormats.NORM, squareNorm); } return new Quaternion(q0 / squareNorm, -q1 / squareNorm, -q2 / squareNorm, -q3 / squareNorm); } Quaternion(final double a,
                      final double b,
                      final double c,
                      final double d);  Quaternion(final double scalar,
                      final double[] v);  Quaternion(final double[] v); Quaternion getConjugate(); static Quaternion multiply(final Quaternion q1, final Quaternion q2); Quaternion multiply(final Quaternion q); static Quaternion add(final Quaternion q1,
                                 final Quaternion q2); Quaternion add(final Quaternion q); static Quaternion subtract(final Quaternion q1,
                                      final Quaternion q2); Quaternion subtract(final Quaternion q); static double dotProduct(final Quaternion q1,
                                    final Quaternion q2); double dotProduct(final Quaternion q); double getNorm(); Quaternion normalize(); @Override boolean equals(Object other); @Override int hashCode(); boolean equals(final Quaternion q,
                          final double eps); boolean isUnitQuaternion(double eps); boolean isPureQuaternion(double eps); Quaternion getPositivePolarForm(); Quaternion getInverse(); double getQ0(); double getQ1(); double getQ2(); double getQ3(); double getScalarPart(); double[] getVectorPart(); Quaternion multiply(final double alpha); @Override String toString(); static final Quaternion IDENTITY; static final Quaternion ZERO; static final Quaternion I; static final Quaternion J; static final Quaternion K; }
@Test public final void testGetInverse() { final Quaternion q = new Quaternion(1.5, 4, 2, -2.5); final Quaternion inverseQ = q.getInverse(); Assert.assertEquals(1.5 / 28.5, inverseQ.getQ0(), 0); Assert.assertEquals(-4.0 / 28.5, inverseQ.getQ1(), 0); Assert.assertEquals(-2.0 / 28.5, inverseQ.getQ2(), 0); Assert.assertEquals(2.5 / 28.5, inverseQ.getQ3(), 0); final Quaternion product = Quaternion.multiply(inverseQ, q); Assert.assertEquals(1, product.getQ0(), EPS); Assert.assertEquals(0, product.getQ1(), EPS); Assert.assertEquals(0, product.getQ2(), EPS); Assert.assertEquals(0, product.getQ3(), EPS); final Quaternion qNul = new Quaternion(0, 0, 0, 0); try { final Quaternion inverseQNul = qNul.getInverse(); Assert.fail("expecting ZeroException but got : " + inverseQNul); } catch (ZeroException ex) { } }