Quaternion implements Serializable { public Quaternion normalize() { final double norm = getNorm(); if (norm < Precision.SAFE_MIN) { throw new ZeroException(LocalizedFormats.NORM, norm); } return new Quaternion(q0 / norm, q1 / norm, q2 / norm, q3 / norm); } 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 testNormalize() { final Quaternion q = new Quaternion(2, 1, -4, -2); final Quaternion versor = q.normalize(); Assert.assertEquals(2.0 / 5.0, versor.getQ0(), 0); Assert.assertEquals(1.0 / 5.0, versor.getQ1(), 0); Assert.assertEquals(-4.0 / 5.0, versor.getQ2(), 0); Assert.assertEquals(-2.0 / 5.0, versor.getQ3(), 0); Assert.assertEquals(1, versor.getNorm(), 0); }
@Test(expected=ZeroException.class) public final void testNormalizeFail() { final Quaternion zeroQ = new Quaternion(0, 0, 0, 0); zeroQ.normalize(); }