/** * Checks if this {@link Vector3} is of unit length with a default * margin of error of 1e-8. * * @return boolean True if this {@link Vector3} is of unit length. */ public boolean isUnit() { return isUnit(1e-8); }
/** * Sets this {@link Quaternion}'s components from the given axis vector and angle around the axis. * * @param axis {@link Vector3} The axis to set rotation on. * @param angle double The rotation angle in degrees. * * @return A reference to this {@link Quaternion} to facilitate chaining. */ @NonNull public Quaternion fromAngleAxis(@NonNull Vector3 axis, double angle) { if (axis.isZero()) { return identity(); } else { mTmpVec1.setAll(axis); if (!mTmpVec1.isUnit()) { mTmpVec1.normalize(); } double radian = MathUtil.degreesToRadians(angle); double halfAngle = radian * .5; double halfAngleSin = Math.sin(halfAngle); w = Math.cos(halfAngle); x = halfAngleSin * mTmpVec1.x; y = halfAngleSin * mTmpVec1.y; z = halfAngleSin * mTmpVec1.z; return this; } }
@Test public void testIsUnitWithMargin() { assertTrue(Vector3.X.isUnit(0.1)); assertTrue(Vector3.Y.isUnit(0.1)); assertTrue(Vector3.Z.isUnit(0.1)); assertFalse((new Vector3(1d)).isUnit(0.1)); assertFalse((new Vector3(0d)).isUnit(0.1)); assertTrue((new Vector3(0.95d, 0d, 0d)).isUnit(0.316227766016838)); assertFalse((new Vector3(0.95d, 0d, 0d)).isUnit(0.05)); }
/** * Checks if this {@link Vector3} is of unit length with a default * margin of error of 1e-8. * * @return boolean True if this {@link Vector3} is of unit length. */ public boolean isUnit() { return isUnit(1e-8); }
/** * Sets this {@link Quaternion}'s components from the given axis vector and angle around the axis. * * @param axis {@link Vector3} The axis to set rotation on. * @param angle double The rotation angle in degrees. * @return A reference to this {@link Quaternion} to facilitate chaining. */ public Quaternion fromAngleAxis(final Vector3 axis, final double angle) { if (!axis.isUnit()) axis.normalize(); double radian = Math.toRadians(angle); //MathUtil.degreesToRadians(angle); double halfAngle = radian * .5; double halfAngleSin = Math.sin(halfAngle); w = Math.cos(halfAngle); x = halfAngleSin * axis.x; y = halfAngleSin * axis.y; z = halfAngleSin * axis.z; return this; }