Otto
September 16, 2022, 6:32pm
1
Hello.
In a math library used by BabylonJs, the distance between a plane and a point is calculated like this
public isFrontFacingTo(direction: DeepImmutable<Vector3>, epsilon: number): boolean {
const dot = Vector3.Dot(this.normal, direction);
return dot <= epsilon;
}
/**
* Calculates the distance to a point
* @param point point to calculate distance to
* @returns the signed distance (float) from the given point to the Plane.
*/
public signedDistanceTo(point: DeepImmutable<Vector3>): number {
return Vector3.Dot(point, this.normal) + this.d;
}
// Statics
/**
* Creates a plane from an array
* @param array the array to create a plane from
* @returns a new Plane from the given array.
*/
static FromArray(array: DeepImmutable<ArrayLike<number>>): Plane {
The formula is quite different than math books gives, and its also outputting different values. Every book gives a formula where a square root is involved eg:
Is the formula accurate?
neu5
September 16, 2022, 6:52pm
2
Hi @Otto ,
Have you checked
return result;
}
/**
* Calculates the distance from a plane and a point
* @param origin origin of the plane to be constructed
* @param normal normal of the plane to be constructed
* @param point point to calculate distance to
* @returns the signed distance between the plane defined by the normal vector at the "origin"" point and the given other point.
*/
static SignedDistanceToPlaneFromPositionAndNormal(origin: DeepImmutable<Vector3>, normal: DeepImmutable<Vector3>, point: DeepImmutable<Vector3>): number {
const d = -(normal.x * origin.x + normal.y * origin.y + normal.z * origin.z);
return Vector3.Dot(point, normal) + d;
}
}
too?
1 Like