@web-engine-dev/math / Plane
Class: Plane
A 3D plane represented by the equation: ax + by + cz + d = 0 where (a, b, c) is the normal and d is the distance from origin. Immutable by design - all operations return new instances.
Example
// Create ground plane at y=0
const ground = new Plane(Vec3.up(), 0);
// Distance from plane (positive = above, negative = below)
const dist = ground.distanceToPoint(point);Constructors
Constructor
new Plane(
normal?,distance?):Plane
Creates a plane from a normal and distance.
Parameters
normal?
Vec3 = ...
The plane normal (should be normalized).
distance?
number = 0
The signed distance from origin along the normal.
Returns
Plane
Properties
distance
readonlydistance:number
normal
readonlynormal:Vec3
Methods
distanceToPoint()
distanceToPoint(
point):number
Returns the signed distance from a point to the plane. Positive if on the side of the normal, negative otherwise.
Parameters
point
Returns
number
equals()
equals(
plane,epsilon?):boolean
Parameters
plane
Plane
epsilon?
number = 0
Returns
boolean
flip()
flip():
Plane
Flips the plane (negates normal and distance).
Returns
Plane
getSide()
getSide(
point,epsilon?):-1|0|1
Checks which side of the plane a point is on.
Parameters
point
epsilon?
number = 1e-6
Returns
-1 | 0 | 1
1 for front (normal side), -1 for back, 0 for on plane.
intersectPlane()
intersectPlane(
other): {direction:Vec3;point:Vec3; } |null
Plane-plane intersection.
Parameters
other
Plane
Returns
{ direction: Vec3; point: Vec3; } | null
Line direction and a point on the line, or null if parallel.
intersectRay()
intersectRay(
origin,direction):Vec3|null
Returns the intersection point of a ray with this plane.
Parameters
origin
direction
Returns
Vec3 | null
intersectsLine()
intersectsLine(
start,end):number|null
Line-plane intersection (line can intersect from either direction).
Parameters
start
end
Returns
number | null
t parameter along line, or null if parallel.
intersectsRay()
intersectsRay(
origin,direction):number|null
Ray-plane intersection.
Parameters
origin
direction
Returns
number | null
t parameter along ray where intersection occurs, or null if no intersection.
isPointOnPositiveSide()
isPointOnPositiveSide(
point):boolean
Checks if a point is on the positive side of the plane (or on it).
Parameters
point
Returns
boolean
normalize()
normalize():
Plane
Returns a normalized version of this plane.
Returns
Plane
projectPoint()
projectPoint(
point):Vec3
Projects a point onto the plane.
Parameters
point
Returns
projectVector()
projectVector(
vector):Vec3
Projects a vector onto the plane (removes the normal component).
Parameters
vector
Returns
reflectPoint()
reflectPoint(
point):Vec3
Reflects a point across the plane.
Parameters
point
Returns
reflectVector()
reflectVector(
vector):Vec3
Reflects a vector across the plane.
Parameters
vector
Returns
setFromCoefficientsMut()
setFromCoefficientsMut(
a,b,c,d):this
Updates this plane from raw coefficients (no allocations).
Parameters
a
number
b
number
c
number
d
number
Returns
this
toCoefficients()
toCoefficients(): [
number,number,number,number]
Returns
[number, number, number, number]
toString()
toString():
string
Returns
string
transform()
transform(
matrix):Plane
Transforms the plane by a matrix.
Parameters
matrix
Returns
Plane
translate()
translate(
offset):Plane
Translates the plane by a vector.
Parameters
offset
Returns
Plane
fromCoefficients()
staticfromCoefficients(a,b,c,d):Plane
Parameters
a
number
b
number
c
number
d
number
Returns
Plane
fromNormalAndPoint()
staticfromNormalAndPoint(normal,point):Plane
Parameters
normal
point
Returns
Plane
fromThreePoints()
staticfromThreePoints(a,b,c):Plane
Parameters
a
b
c
Returns
Plane
xy()
staticxy():Plane
Returns
Plane
xz()
staticxz():Plane
Returns
Plane
yz()
staticyz():Plane
Returns
Plane