/** * Updates this quaternion from the given Euler rotation angles, applied in the given order: heading, attitude, * bank. * * @param angles * the Euler angles of rotation (in radians) stored as heading, attitude, and bank. * @return this quaternion for chaining * @throws ArrayIndexOutOfBoundsException * if angles is less than length 3 * @throws NullPointerException * if angles is null. */ public Quaternion fromEulerAngles(final double[] angles) { return fromEulerAngles(angles[0], angles[1], angles[2]); }
/** * Updates this quaternion from the given Euler rotation angles, applied in the given order: heading, attitude, * bank. * * @param angles * the Euler angles of rotation (in radians) stored as heading, attitude, and bank. * @return this quaternion for chaining * @throws ArrayIndexOutOfBoundsException * if angles is less than length 3 * @throws NullPointerException * if angles is null. */ public Quaternion fromEulerAngles(final double[] angles) { return fromEulerAngles(angles[0], angles[1], angles[2]); }
@Test(expected = ArrayIndexOutOfBoundsException.class) public void testBadEuler1() { new Quaternion().fromEulerAngles(new double[2]); }
@Test public void testEulerAngles() { final Quaternion quat = new Quaternion().fromEulerAngles(new double[] { MathUtils.HALF_PI, 0, 0 }); assertTrue(1.0 == quat.magnitude()); assertTrue(Math.abs(Vector3.NEG_UNIT_Z.distance(quat.apply(Vector3.UNIT_X, null))) <= MathUtils.EPSILON); quat.fromEulerAngles(0, -MathUtils.HALF_PI, 0); assertTrue(1.0 == quat.magnitude()); assertTrue(Math.abs(Vector3.NEG_UNIT_Y.distance(quat.apply(Vector3.UNIT_X, null))) <= MathUtils.EPSILON); quat.fromEulerAngles(0, 0, MathUtils.HALF_PI); assertTrue(1.0 == quat.magnitude()); assertTrue(Math.abs(Vector3.UNIT_Z.distance(quat.apply(Vector3.UNIT_Y, null))) <= MathUtils.EPSILON); quat.fromEulerAngles(0, MathUtils.HALF_PI, 0); double[] angles = quat.toEulerAngles(null); final Quaternion quat2 = new Quaternion().fromEulerAngles(angles); assertEquals(quat, quat2); quat.fromEulerAngles(0, -MathUtils.HALF_PI, 0); angles = quat.toEulerAngles(null); quat2.fromEulerAngles(angles); assertEquals(quat, quat2); quat.fromEulerAngles(0, 0, MathUtils.HALF_PI); angles = quat.toEulerAngles(null); quat2.fromEulerAngles(angles); assertEquals(quat, quat2); }
quat.fromEulerAngles(MathUtils.QUARTER_PI, MathUtils.PI, MathUtils.HALF_PI); final Vector3 rotated = new Vector3(1, 1, 1); quat.apply(rotated, rotated);