/** * 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)); }
@Override // from IBox public boolean intersection (IRay3 ray, Vector3 result) { IVector3 origin = ray.origin(); if (contains(origin)) { result.set(origin); return true; } IVector3 dir = ray.direction(); float t = Float.MAX_VALUE; if (Math.abs(dir.x()) > MathUtil.EPSILON) { t = Math.min(t, intersectionX(ray, _minExtent.x)); t = Math.min(t, intersectionX(ray, _maxExtent.x)); } if (Math.abs(dir.y()) > MathUtil.EPSILON) { t = Math.min(t, intersectionY(ray, _minExtent.y)); t = Math.min(t, intersectionY(ray, _maxExtent.y)); } if (Math.abs(dir.z()) > MathUtil.EPSILON) { t = Math.min(t, intersectionZ(ray, _minExtent.z)); t = Math.min(t, intersectionZ(ray, _maxExtent.z)); } if (t == Float.MAX_VALUE) { return false; } origin.addScaled(dir, t, result); return true; }
/** * 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 a point on the plane and the plane normal. * * @return a reference to the plane (for chaining). */ public Plane fromPointNormal (IVector3 pt, IVector3 normal) { return set(normal, -normal.dot(pt)); }
@Override // from IPlane public boolean intersection (IRay3 ray, Vector3 result) { float distance = distance(ray); if (Float.isNaN(distance) || distance < 0f) { return false; } else { ray.origin().addScaled(ray.direction(), distance, result); return true; } }
@Override // from IBox public float extentDistance (IBox other) { return other.minimumExtent().manhattanDistance(_minExtent) + other.maximumExtent().manhattanDistance(_maxExtent); }
@Override // from interface IVector3 public float angle (IVector3 other) { return FloatMath.acos(dot(other) / (length() * other.length())); }
/** * 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)); }
@Override // from IBox public boolean intersection (IRay3 ray, Vector3 result) { IVector3 origin = ray.origin(); if (contains(origin)) { result.set(origin); return true; } IVector3 dir = ray.direction(); float t = Float.MAX_VALUE; if (Math.abs(dir.x()) > MathUtil.EPSILON) { t = Math.min(t, intersectionX(ray, _minExtent.x)); t = Math.min(t, intersectionX(ray, _maxExtent.x)); } if (Math.abs(dir.y()) > MathUtil.EPSILON) { t = Math.min(t, intersectionY(ray, _minExtent.y)); t = Math.min(t, intersectionY(ray, _maxExtent.y)); } if (Math.abs(dir.z()) > MathUtil.EPSILON) { t = Math.min(t, intersectionZ(ray, _minExtent.z)); t = Math.min(t, intersectionZ(ray, _maxExtent.z)); } if (t == Float.MAX_VALUE) { return false; } origin.addScaled(dir, t, result); return true; }
/** * 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 a point on the plane and the plane normal. * * @return a reference to the plane (for chaining). */ public Plane fromPointNormal (IVector3 pt, IVector3 normal) { return set(normal, -normal.dot(pt)); }
@Override // from IPlane public boolean intersection (IRay3 ray, Vector3 result) { float distance = distance(ray); if (Float.isNaN(distance) || distance < 0f) { return false; } else { ray.origin().addScaled(ray.direction(), distance, result); return true; } }
@Override // from IBox public float extentDistance (IBox other) { return other.minimumExtent().manhattanDistance(_minExtent) + other.maximumExtent().manhattanDistance(_maxExtent); }
@Override // from interface IVector3 public float angle (IVector3 other) { return FloatMath.acos(dot(other) / (length() * other.length())); }
/** * 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)); }