@Override // from interface IVector3 public Vector3 normalize (Vector3 result) { return mult(1f / length(), result); }
@Override // from interface IVector3 public Vector3 normalize (Vector3 result) { return mult(1f / length(), result); }
@Override // from interface IVector3 public float angle (IVector3 other) { return FloatMath.acos(dot(other) / (length() * other.length())); }
@Override // from interface IVector3 public float angle (IVector3 other) { return FloatMath.acos(dot(other) / (length() * other.length())); }
/** * Sets this quaternion to the rotation of the first normalized vector onto the second. * * @return a reference to this quaternion, for chaining. */ public Quaternion fromVectors (IVector3 from, IVector3 to) { float angle = from.angle(to); if (angle < MathUtil.EPSILON) { return set(IDENTITY); } if (angle <= FloatMath.PI - MathUtil.EPSILON) { return fromAngleAxis(angle, from.cross(to).normalizeLocal()); } // it's a 180 degree rotation; any axis orthogonal to the from vector will do Vector3 axis = new Vector3(0f, from.z(), -from.y()); float length = axis.length(); return fromAngleAxis(FloatMath.PI, length < MathUtil.EPSILON ? axis.set(-from.z(), 0f, from.x()).normalizeLocal() : axis.multLocal(1f / length)); }
/** * Sets this quaternion to the rotation of the first normalized vector onto the second. * * @return a reference to this quaternion, for chaining. */ public Quaternion fromVectors (IVector3 from, IVector3 to) { float angle = from.angle(to); if (angle < MathUtil.EPSILON) { return set(IDENTITY); } if (angle <= FloatMath.PI - MathUtil.EPSILON) { return fromAngleAxis(angle, from.cross(to).normalizeLocal()); } // it's a 180 degree rotation; any axis orthogonal to the from vector will do Vector3 axis = new Vector3(0f, from.z(), -from.y()); float length = axis.length(); return fromAngleAxis(FloatMath.PI, length < MathUtil.EPSILON ? axis.set(-from.z(), 0f, from.x()).normalizeLocal() : axis.multLocal(1f / length)); }
/** * Sets this to a rotation matrix that rotates one vector onto another. * * @return a reference to this matrix, for chaining. */ public Matrix4 setToRotation (IVector3 from, IVector3 to) { float angle = from.angle(to); if (angle < MathUtil.EPSILON) { return setToIdentity(); } if (angle <= FloatMath.PI - MathUtil.EPSILON) { return setToRotation(angle, from.cross(to).normalizeLocal()); } // it's a 180 degree rotation; any axis orthogonal to the from vector will do Vector3 axis = new Vector3(0f, from.z(), -from.y()); float length = axis.length(); return setToRotation(FloatMath.PI, length < MathUtil.EPSILON ? axis.set(-from.z(), 0f, from.x()).normalizeLocal() : axis.multLocal(1f / length)); }
/** * Sets this to a rotation matrix that rotates one vector onto another. * * @return a reference to this matrix, for chaining. */ public Matrix4 setToRotation (IVector3 from, IVector3 to) { float angle = from.angle(to); if (angle < MathUtil.EPSILON) { return setToIdentity(); } if (angle <= FloatMath.PI - MathUtil.EPSILON) { return setToRotation(angle, from.cross(to).normalizeLocal()); } // it's a 180 degree rotation; any axis orthogonal to the from vector will do Vector3 axis = new Vector3(0f, from.z(), -from.y()); float length = axis.length(); return setToRotation(FloatMath.PI, length < MathUtil.EPSILON ? axis.set(-from.z(), 0f, from.x()).normalizeLocal() : axis.multLocal(1f / length)); }