Quaternion { public Vector3 applyTo(Vector3 p1) { double zSq = z * z; double xSq = x * x; double ySQ = y * y; double wSq = w * w; double resultX = 2 * (w * (y * p1.getZ() - z * p1.getY()) + x * (y * p1.getY() + z * p1.getZ())) - zSq * p1.getX() - ySQ * p1.getX() + wSq * p1.getX() + xSq * p1.getX(); double resultY = 2 * (y * (x * p1.getX() + z * p1.getZ()) + w * (z * p1.getX() - x * p1.getZ())) - xSq * p1.getY() + ySQ * p1.getY() - zSq * p1.getY() + wSq * p1.getY(); double resultZ = 2 * (z * (x * p1.getX() + y * p1.getY()) + w * (x * p1.getY() - y * p1.getX())) - xSq * p1.getZ() + wSq * p1.getZ() + zSq * p1.getZ() - ySQ * p1.getZ(); return new Vector3(resultX, resultY, resultZ); } Quaternion(final Quaternion source);  Quaternion(final double x, final double y, final double z, final double w);  Quaternion(double x, double y, double z, double w, boolean needsNormalization); static Quaternion fromAngleAxis(final double angle, final Vector3 axis); static Quaternion fromAngleAxis(Vector3 angels); static Quaternion fromAngleNormalAxis(final double angle, final Vector3 axis); static Quaternion fromAxes(final Vector3[] axes); static Quaternion fromAxes(final Vector3 xAxis, final Vector3 yAxis, final Vector3 zAxis); static Quaternion lookAt(final Vector3 direction, final Vector3 up); double getX(); double getY(); double getZ(); double getW(); double[] toArray(final double[] store); double[][] getMatrix(); Quaternion fromEulerAngles(final double[] angles); static Quaternion fromEulerAngles(final double heading, final double attitude, final double bank); double[] toEulerAngles(final double[] store); static Quaternion fromRotationMatrix(final Matrix3 matrix); static Quaternion fromRotationMatrix(final double m00, final double m01, final double m02, final double m10,
												final double m11, final double m12, final double m20, final double m21, final double m22); Matrix3 toRotationMatrix3(); Matrix4 toRotationMatrix4(); Vector3 getRotationColumn(final int index); Vector3 toAngleAxis(); double toAngle(); Quaternion fromVectorToVector(final Vector3 from, final Vector3 to); Quaternion normalize(); Quaternion invert(); Quaternion conjugate(); Quaternion add(final Quaternion quat); Quaternion subtract(final Quaternion quat); Quaternion multiply(final double scalar); Quaternion multiply(final Quaternion quat); Vector3 applyTo(Vector3 p1); Quaternion applyTo(Quaternion r); Quaternion applyInverseTo(Quaternion r); Vector3[] toAxes(); Quaternion slerp(final Quaternion endQuat, final double changeAmnt); static Quaternion slerp(final Quaternion startQuat, final Quaternion endQuat, final double changeAmnt); double magnitudeSquared(); double magnitude(); double dot(final double x, final double y, final double z, final double w); double dot(final Quaternion quat); boolean isIdentity(); static boolean isValid(final Quaternion quat); @Override int hashCode(); @Override boolean equals(final Object o); @Override String toString(); static final Quaternion IDENTITY; }
@Test public void testRotationOfVector2() { Vector3 ardor = new Vector3(0, 0, 9); Vector3 spacedVector = new Vector3(0, 0, 9); assertSameVectors(ardor, spacedVector); Quaternion ardorRot = new Quaternion(0.0, 0.19866933079506122, 0.0, 0.9800665778412416); Quaternion spacedRot = new Quaternion(0.0, 0.19866933079506122, 0.0, 0.9800665778412416); assertSameRotations(ardorRot, spacedRot); Vector3 ardorResult = ardorRot.applyTo(ardor); Vector3 spacedResult = spacedRot.applyTo(spacedVector); assertSameVectors(ardorResult, spacedResult); }