Skip to content

@web-engine-dev/math


@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

ts
// 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

readonly distance: number


normal

readonly normal: 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

Vec3

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

Vec3

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

Vec3

direction

Vec3

Returns

Vec3 | null


intersectsLine()

intersectsLine(start, end): number | null

Line-plane intersection (line can intersect from either direction).

Parameters

start

Vec3

end

Vec3

Returns

number | null

t parameter along line, or null if parallel.


intersectsRay()

intersectsRay(origin, direction): number | null

Ray-plane intersection.

Parameters

origin

Vec3

direction

Vec3

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

Vec3

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

Vec3

Returns

Vec3


projectVector()

projectVector(vector): Vec3

Projects a vector onto the plane (removes the normal component).

Parameters

vector

Vec3

Returns

Vec3


reflectPoint()

reflectPoint(point): Vec3

Reflects a point across the plane.

Parameters

point

Vec3

Returns

Vec3


reflectVector()

reflectVector(vector): Vec3

Reflects a vector across the plane.

Parameters

vector

Vec3

Returns

Vec3


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

Mat4

Returns

Plane


translate()

translate(offset): Plane

Translates the plane by a vector.

Parameters

offset

Vec3

Returns

Plane


fromCoefficients()

static fromCoefficients(a, b, c, d): Plane

Parameters

a

number

b

number

c

number

d

number

Returns

Plane


fromNormalAndPoint()

static fromNormalAndPoint(normal, point): Plane

Parameters

normal

Vec3

point

Vec3

Returns

Plane


fromThreePoints()

static fromThreePoints(a, b, c): Plane

Parameters

a

Vec3

b

Vec3

c

Vec3

Returns

Plane


xy()

static xy(): Plane

Returns

Plane


xz()

static xz(): Plane

Returns

Plane


yz()

static yz(): Plane

Returns

Plane

Proprietary software. All rights reserved.