/** * @return the magnitude of this quaternion. basically sqrt({@link #magnitude()}) */ @Override public double magnitude() { final double magnitudeSQ = magnitudeSquared(); if (magnitudeSQ == 1.0) { return 1.0; } return MathUtils.sqrt(magnitudeSQ); }
/** * @return the magnitude of this quaternion. basically sqrt({@link #magnitude()}) */ @Override public double magnitude() { final double magnitudeSQ = magnitudeSquared(); if (magnitudeSQ == 1.0) { return 1.0; } return MathUtils.sqrt(magnitudeSQ); }
/** * 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); } }
final double norm = magnitudeSquared(); final double s = norm == 1.0 ? 2.0 : norm > 0.0 ? 2.0 / norm : 0;
final double norm = magnitudeSquared(); final double s = norm == 1.0 ? 2.0 : norm > 0.0 ? 2.0 / norm : 0;
final double norm = magnitudeSquared(); final double s = norm == 1.0 ? 2.0 : norm > 0.0 ? 2.0 / norm : 0;
final double norm = magnitudeSquared(); final double s = norm > 0.0 ? 2.0 / norm : 0.0;
final double norm = magnitudeSquared(); final double s = norm == 1.0 ? 2.0 : norm > 0.0 ? 2.0 / norm : 0;
final double norm = magnitudeSquared(); final double s = norm > 0.0 ? 2.0 / norm : 0.0;