/** * Locally sets this quaternion <code>Q</code> to its <i>multiplicative inverse</i> <code>Q<sup>-1</sup></code> such * that <code>QQ<sup>-1</sup> = [0,0,0,1]</code> (the identity quaternion). Note that for unit quaternions, a * quaternion's inverse is equal to its (far easier to calculate) conjugate. * * @see #conjugate(Quaternion) * * @return this <code>Quaternion</code> for chaining. */ public Quaternion invertLocal() { final double magnitudeSQ = magnitudeSquared(); conjugateLocal(); if (Math.abs(1.0 - magnitudeSQ) <= MathUtils.EPSILON) { return this; } else { return multiplyLocal(1.0 / magnitudeSquared()); } }
/** * Locally sets this quaternion <code>Q</code> to its <i>multiplicative inverse</i> <code>Q<sup>-1</sup></code> such * that <code>QQ<sup>-1</sup> = [0,0,0,1]</code> (the identity quaternion). Note that for unit quaternions, a * quaternion's inverse is equal to its (far easier to calculate) conjugate. * * @see #conjugate(Quaternion) * * @return this <code>Quaternion</code> for chaining. */ public Quaternion invertLocal() { final double magnitudeSQ = magnitudeSquared(); conjugateLocal(); if (Math.abs(1.0 - magnitudeSQ) <= MathUtils.EPSILON) { return this; } else { return multiplyLocal(1.0 / magnitudeSquared()); } }
/** * Calculates the <i>multiplicative inverse</i> <code>Q<sup>-1</sup></code> of this quaternion <code>Q</code> such * that <code>QQ<sup>-1</sup> = [0,0,0,1]</code> (the identity quaternion). Note that for unit quaternions, a * quaternion's inverse is equal to its (far easier to calculate) conjugate. * * @param store * the <code>Quaternion</code> to store the result in. If <code>null</code>, a new one is created. * @see #conjugate(Quaternion) * @return the multiplicative inverse of this quaternion. */ public Quaternion invert(Quaternion store) { if (store == null) { store = new Quaternion(); } final double magnitudeSQ = magnitudeSquared(); conjugate(store); if (Math.abs(1.0 - magnitudeSQ) <= MathUtils.EPSILON) { return store; } else { return store.multiplyLocal(1.0 / magnitudeSQ); } }
/** * Calculates the <i>multiplicative inverse</i> <code>Q<sup>-1</sup></code> of this quaternion <code>Q</code> such * that <code>QQ<sup>-1</sup> = [0,0,0,1]</code> (the identity quaternion). Note that for unit quaternions, a * quaternion's inverse is equal to its (far easier to calculate) conjugate. * * @param store * the <code>Quaternion</code> to store the result in. If <code>null</code>, a new one is created. * @see #conjugate(Quaternion) * @return the multiplicative inverse of this quaternion. */ public Quaternion invert(Quaternion store) { if (store == null) { store = new Quaternion(); } final double magnitudeSQ = magnitudeSquared(); conjugate(store); if (Math.abs(1.0 - magnitudeSQ) <= MathUtils.EPSILON) { return store; } else { return store.multiplyLocal(1.0 / magnitudeSQ); } }
/** * Multiplies this quaternion by the supplied quaternion. The result is stored locally. * * @param quat * The Quaternion to multiply this one by. * @return this quaternion for chaining * @throws NullPointerException * if quat is null. */ public Quaternion multiplyLocal(final ReadOnlyQuaternion quat) { return multiplyLocal(quat.getX(), quat.getY(), quat.getZ(), quat.getW()); }
/** * Multiplies this quaternion by the supplied quaternion. The result is stored locally. * * @param quat * The Quaternion to multiply this one by. * @return this quaternion for chaining * @throws NullPointerException * if quat is null. */ public Quaternion multiplyLocal(final ReadOnlyQuaternion quat) { return multiplyLocal(quat.getX(), quat.getY(), quat.getZ(), quat.getW()); }
@Test public void testMultiply() { final Quaternion quat1 = new Quaternion(0.5, 1, 2, 3); final Quaternion quat2 = new Quaternion(); assertEquals(new Quaternion(1, 2, 4, 6), quat1.multiply(2, null)); assertEquals(new Quaternion(2, 4, 8, 12), quat1.multiply(4, quat2)); assertEquals(new Quaternion(1, 2, 4, 6), quat1.multiplyLocal(2)); quat1.fromAngleNormalAxis(MathUtils.QUARTER_PI, Vector3.UNIT_Y); quat1.multiply(quat1, quat2); final ReadOnlyVector3 vec = Vector3.UNIT_Z; assertTrue(Math.abs(Vector3.UNIT_X.distance(quat2.apply(vec, null))) <= Quaternion.ALLOWED_DEVIANCE); quat1.multiplyLocal(quat1.getX(), quat1.getY(), quat1.getZ(), quat1.getW()); assertTrue(Math.abs(Vector3.UNIT_X.distance(quat1.apply(vec, null))) <= Quaternion.ALLOWED_DEVIANCE); quat2.fromAngleNormalAxis(MathUtils.HALF_PI, Vector3.UNIT_Y); quat1.multiplyLocal(quat2); assertTrue(Math.abs(Vector3.NEG_UNIT_Z.distance(quat1.apply(vec, null))) <= Quaternion.ALLOWED_DEVIANCE); quat1.multiplyLocal(new Matrix3().applyRotationY(MathUtils.HALF_PI)); assertTrue(Math.abs(Vector3.NEG_UNIT_X.distance(quat1.apply(vec, null))) <= Quaternion.ALLOWED_DEVIANCE); }
result.multiplyLocal(-1); dotP = -dotP;
result.multiplyLocal(-1); dotP = -dotP;
workQuat.multiplyLocal(-1); result = -result;
workQuat.multiplyLocal(-1); result = -result;
kQ1.multiplyLocal(-1.0);