/** * Sets this to a rotation matrix that rotates one vector onto another. * * @return a reference to this matrix, for chaining. */ public Matrix3 setToRotation (IVector3 from, IVector3 to) { float angle = from.angle(to); return (angle < 0.0001f) ? setToIdentity() : setToRotation(angle, from.cross(to).normalizeLocal()); }
/** * Sets this to a rotation matrix that rotates one vector onto another. * * @return a reference to this matrix, for chaining. */ public Matrix3 setToRotation (IVector3 from, IVector3 to) { float angle = from.angle(to); return (angle < 0.0001f) ? setToIdentity() : setToRotation(angle, from.cross(to).normalizeLocal()); }
/** * Sets this plane based on the three points provided. * * @return a reference to the plane (for chaining). */ public Plane fromPoints (IVector3 p1, IVector3 p2, IVector3 p3) { // compute the normal by taking the cross product of the two vectors formed p2.subtract(p1, _v1); p3.subtract(p1, _v2); _v1.cross(_v2, _normal).normalizeLocal(); // use the first point to determine the constant constant = -_normal.dot(p1); return this; }
/** * Sets this plane based on the three points provided. * * @return a reference to the plane (for chaining). */ public Plane fromPoints (IVector3 p1, IVector3 p2, IVector3 p3) { // compute the normal by taking the cross product of the two vectors formed p2.subtract(p1, _v1); p3.subtract(p1, _v2); _v1.cross(_v2, _normal).normalizeLocal(); // use the first point to determine the constant constant = -_normal.dot(p1); return this; }
/** * 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)); }
/** * 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)); }