/** Returns whether the plane is facing the direction vector. Think of the direction vector as the direction a camera looks in. * This method will return true if the front side of the plane determined by its normal faces the camera. * * @param direction the direction * @return whether the plane is front facing */ public boolean isFrontFacing (Vector3 direction) { float dot = normal.dot(direction); return dot <= 0; }
/** Calculates the shortest signed distance between the plane and the given point. * * @param point The point * @return the shortest signed distance between the plane and the point */ public float distance (Vector3 point) { return normal.dot(point) + d; }
/** Calculates the shortest signed distance between the plane and the given point. * * @param point The point * @return the shortest signed distance between the plane and the point */ public float distance (Vector3 point) { return normal.dot(point) + d; }
/** Returns whether the plane is facing the direction vector. Think of the direction vector as the direction a camera looks in. * This method will return true if the front side of the plane determined by its normal faces the camera. * * @param direction the direction * @return whether the plane is front facing */ public boolean isFrontFacing (Vector3 direction) { float dot = normal.dot(direction); return dot <= 0; }
/** Sets the plane to the given point and normal. * * @param point the point on the plane * @param normal the normal of the plane */ public void set (Vector3 point, Vector3 normal) { this.normal.set(normal); d = -point.dot(normal); }
/** Sets the plane to the given point and normal. * * @param point the point on the plane * @param normal the normal of the plane */ public void set (Vector3 point, Vector3 normal) { this.normal.set(normal); d = -point.dot(normal); }
@Override public boolean isPerpendicular (Vector3 vector) { return MathUtils.isZero(dot(vector)); }
@Override public boolean isPerpendicular (Vector3 vector) { return MathUtils.isZero(dot(vector)); }
/** Set this quaternion to the rotation between two vectors. * @param v1 The base vector, which should be normalized. * @param v2 The target vector, which should be normalized. * @return This quaternion for chaining */ public Quaternion setFromCross (final Vector3 v1, final Vector3 v2) { final float dot = MathUtils.clamp(v1.dot(v2), -1f, 1f); final float angle = (float)Math.acos(dot); return setFromAxisRad(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x, angle); }
/** Set this quaternion to the rotation between two vectors. * @param v1 The base vector, which should be normalized. * @param v2 The target vector, which should be normalized. * @return This quaternion for chaining */ public Quaternion setFromCross (final Vector3 v1, final Vector3 v2) { final float dot = MathUtils.clamp(v1.dot(v2), -1f, 1f); final float angle = (float)Math.acos(dot); return setFromAxisRad(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x, angle); }
/** Set this quaternion to the rotation between two vectors. * @param x1 The base vectors x value, which should be normalized. * @param y1 The base vectors y value, which should be normalized. * @param z1 The base vectors z value, which should be normalized. * @param x2 The target vector x value, which should be normalized. * @param y2 The target vector y value, which should be normalized. * @param z2 The target vector z value, which should be normalized. * @return This quaternion for chaining */ public Quaternion setFromCross (final float x1, final float y1, final float z1, final float x2, final float y2, final float z2) { final float dot = MathUtils.clamp(Vector3.dot(x1, y1, z1, x2, y2, z2), -1f, 1f); final float angle = (float)Math.acos(dot); return setFromAxisRad(y1 * z2 - z1 * y2, z1 * x2 - x1 * z2, x1 * y2 - y1 * x2, angle); }
/** Set this quaternion to the rotation between two vectors. * @param x1 The base vectors x value, which should be normalized. * @param y1 The base vectors y value, which should be normalized. * @param z1 The base vectors z value, which should be normalized. * @param x2 The target vector x value, which should be normalized. * @param y2 The target vector y value, which should be normalized. * @param z2 The target vector z value, which should be normalized. * @return This quaternion for chaining */ public Quaternion setFromCross (final float x1, final float y1, final float z1, final float x2, final float y2, final float z2) { final float dot = MathUtils.clamp(Vector3.dot(x1, y1, z1, x2, y2, z2), -1f, 1f); final float angle = (float)Math.acos(dot); return setFromAxisRad(y1 * z2 - z1 * y2, z1 * x2 - x1 * z2, x1 * y2 - y1 * x2, angle); }
/** Constructs a new plane based on the normal and a point on the plane. * * @param normal The normal * @param point The point on the plane */ public Plane (Vector3 normal, Vector3 point) { this.normal.set(normal).nor(); this.d = -this.normal.dot(point); }
/** Get the angle in radians of the rotation around the specified axis. The axis must be normalized. * @param axisX the x component of the normalized axis for which to get the angle * @param axisY the y component of the normalized axis for which to get the angle * @param axisZ the z component of the normalized axis for which to get the angle * @return the angle in radians of the rotation around the specified axis */ public float getAngleAroundRad (final float axisX, final float axisY, final float axisZ) { final float d = Vector3.dot(this.x, this.y, this.z, axisX, axisY, axisZ); final float l2 = Quaternion.len2(axisX * d, axisY * d, axisZ * d, this.w); return MathUtils.isZero(l2) ? 0f : (float)(2.0 * Math.acos(MathUtils.clamp( (float)((d < 0 ? -this.w : this.w) / Math.sqrt(l2)), -1f, 1f))); }
/** Get the angle in radians of the rotation around the specified axis. The axis must be normalized. * @param axisX the x component of the normalized axis for which to get the angle * @param axisY the y component of the normalized axis for which to get the angle * @param axisZ the z component of the normalized axis for which to get the angle * @return the angle in radians of the rotation around the specified axis */ public float getAngleAroundRad (final float axisX, final float axisY, final float axisZ) { final float d = Vector3.dot(this.x, this.y, this.z, axisX, axisY, axisZ); final float l2 = Quaternion.len2(axisX * d, axisY * d, axisZ * d, this.w); return MathUtils.isZero(l2) ? 0f : (float)(2.0 * Math.acos(MathUtils.clamp( (float)((d < 0 ? -this.w : this.w) / Math.sqrt(l2)), -1f, 1f))); }
/** Constructs a new plane based on the normal and a point on the plane. * * @param normal The normal * @param point The point on the plane */ public Plane (Vector3 normal, Vector3 point) { this.normal.set(normal).nor(); this.d = -this.normal.dot(point); }
public static boolean intersectSegmentPlane (Vector3 start, Vector3 end, Plane plane, Vector3 intersection) { Vector3 dir = v0.set(end).sub(start); float denom = dir.dot(plane.getNormal()); if (denom == 0f) return false; float t = -(start.dot(plane.getNormal()) + plane.getD()) / denom; if (t < 0 || t > 1) return false; intersection.set(start).add(dir.scl(t)); return true; }
/** Sets the plane normal and distance to the origin based on the three given points which are considered to be on the plane. * The normal is calculated via a cross product between (point1-point2)x(point2-point3) * * @param point1 * @param point2 * @param point3 */ public void set (Vector3 point1, Vector3 point2, Vector3 point3) { normal.set(point1).sub(point2).crs(point2.x-point3.x, point2.y-point3.y, point2.z-point3.z).nor(); d = -point1.dot(normal); }
/** Sets the plane normal and distance to the origin based on the three given points which are considered to be on the plane. * The normal is calculated via a cross product between (point1-point2)x(point2-point3) * * @param point1 * @param point2 * @param point3 */ public void set (Vector3 point1, Vector3 point2, Vector3 point3) { normal.set(point1).sub(point2).crs(point2.x-point3.x, point2.y-point3.y, point2.z-point3.z).nor(); d = -point1.dot(normal); }
public static boolean intersectSegmentPlane (Vector3 start, Vector3 end, Plane plane, Vector3 intersection) { Vector3 dir = v0.set(end).sub(start); float denom = dir.dot(plane.getNormal()); if (denom == 0f) return false; float t = -(start.dot(plane.getNormal()) + plane.getD()) / denom; if (t < 0 || t > 1) return false; intersection.set(start).add(dir.scl(t)); return true; }