/** * Sets the values of this quaternion to the values represented by a given angle and unit length axis of rotation. * If axis == 0,0,0 the quaternion is set to identity. * * @param angle * the angle to rotate (in radians). * @param axis * the axis of rotation (already normalized - unit length). * @throws NullPointerException * if axis is null */ public Quaternion fromAngleNormalAxis(final double angle, final ReadOnlyVector3 axis) { if (axis.equals(Vector3.ZERO)) { return setIdentity(); } final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double w = MathUtils.cos(halfAngle); final double x = sin * axis.getX(); final double y = sin * axis.getY(); final double z = sin * axis.getZ(); return set(x, y, z, w); }
/** * Sets the values of this quaternion to the values represented by a given angle and unit length axis of rotation. * If axis == 0,0,0 the quaternion is set to identity. * * @param angle * the angle to rotate (in radians). * @param axis * the axis of rotation (already normalized - unit length). * @throws NullPointerException * if axis is null */ public Quaternion fromAngleNormalAxis(final double angle, final ReadOnlyVector3 axis) { if (axis.equals(Vector3.ZERO)) { return setIdentity(); } final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double w = MathUtils.cos(halfAngle); final double x = sin * axis.getX(); final double y = sin * axis.getY(); final double z = sin * axis.getZ(); return set(x, y, z, w); }
return setIdentity();
quat2.setIdentity().applyRotationZ(MathUtils.PI); quat.slerp(quat2, 1.0, store); assertTrue(Math.abs(new Vector3(-1, 0, 0).distance(store.apply(Vector3.UNIT_X, null))) <= Quaternion.ALLOWED_DEVIANCE); quat2.setIdentity().applyRotationZ(MathUtils.PI); quat.slerp(quat2, .5, store); assertTrue(Math.abs(new Vector3(0, 1, 0).distance(store.apply(Vector3.UNIT_X, null))) <= Quaternion.ALLOWED_DEVIANCE); quat2.setIdentity().applyRotationZ(MathUtils.PI); quat.slerp(quat2, 0, store); assertTrue(Math.abs(new Vector3(1, 0, 0).distance(store.apply(Vector3.UNIT_X, null))) <= Quaternion.ALLOWED_DEVIANCE); quat2.setIdentity(); quat.slerp(quat2, 0.25, store); assertTrue(Math.abs(new Vector3(1, 0, 0).distance(store.apply(Vector3.UNIT_X, null))) <= Quaternion.ALLOWED_DEVIANCE); quat.setIdentity().applyRotationX(-2 * MathUtils.HALF_PI); quat2.setIdentity().applyRotationX(MathUtils.HALF_PI); quat.slerp(quat2, 0.5, store); assertTrue(Math.abs(new Vector3(0, -Math.sin(MathUtils.QUARTER_PI), Math.sin(MathUtils.QUARTER_PI)) quat2.setIdentity().applyRotationX(MathUtils.PI); quat.slerpLocal(quat2, 1.0); assertTrue(Math.abs(new Vector3(0, -1, 0).distance(quat.apply(Vector3.UNIT_Y, null))) <= Quaternion.ALLOWED_DEVIANCE); quat.setIdentity(); quat.slerpLocal(quat2, .5); assertTrue(Math.abs(new Vector3(0, 0, 1).distance(quat.apply(Vector3.UNIT_Y, null))) <= Quaternion.ALLOWED_DEVIANCE);
worker.setIdentity().applyRotationX(MathUtils.QUARTER_PI).apply(expected, expected); worker.setIdentity().applyRotation(MathUtils.QUARTER_PI, 1, 0, 0).apply(rotated, rotated); assertTrue(rotated.distance(expected) <= MathUtils.EPSILON); worker.setIdentity().applyRotationY(MathUtils.QUARTER_PI).apply(expected, expected); worker.setIdentity().applyRotation(MathUtils.QUARTER_PI, 0, 1, 0).apply(rotated, rotated); assertTrue(rotated.distance(expected) <= MathUtils.EPSILON); worker.setIdentity().applyRotationZ(MathUtils.QUARTER_PI).apply(expected, expected); worker.setIdentity().applyRotation(MathUtils.QUARTER_PI, 0, 0, 1).apply(rotated, rotated); assertTrue(rotated.distance(expected) <= MathUtils.EPSILON);
assertFalse(Quaternion.isValid(quat)); quat.setIdentity(); assertTrue(Quaternion.isValid(quat));