Initializing 3D Canvas...

The Plane

1 min read1 page

Infinite Flatness

A plane is a flat, two-dimensional surface that extends infinitely in 3D space. It is defined by an origin point and a perpendicular Normal Vector.

While a plane mathematically extends forever, we typically visualize it as a finite rectangular boundary to understand its orientation and local axes.

1 min read1 page

Memory & Storage

A plane requires surprisingly little data. You only need a Point (where it is) and a Vector (which way it faces).

python
1class Plane:
2 def __init__(self, origin: 'Point3d', normal: 'Vector3d'):
3 self.Origin = origin
4 # The normal vector defines the "up" direction
5 # and perfectly locks the plane's rotation
6 self.Normal = normal.Unitize()
1 min read1 page

BasisVectors:

When you define a Normal vector, the computer automatically calculates an X-Axis and Y-Axis that lay perfectly flat on the plane surface. This gives the plane its own internal 2D coordinate system.
python
1class Plane:
2 # A plane implies a local coordinate system
3 @property
4 def XAxis(self) -> 'Vector3d':
5 return self._xAxis
6
7 @property
8 def YAxis(self) -> 'Vector3d':
9 return self._yAxis
10
11 @property
12 def ZAxis(self) -> 'Vector3d':
13 return self.Normal
2 min read1 page

Equation:

In pure mathematics and some engines, a plane isn't defined by an Origin and Normal. It's defined by the equation Ax + By + Cz + D = 0.
python
1class Plane:
2 def __init__(self, a: float, b: float, c: float, d: float):
3 """Constructs a plane from its mathematical equation."""
4 # The equation of a plane is Ax + By + Cz + D = 0
5
6 # A, B, C represent the Normal Vector!
7 self.Normal = Vector3d(a, b, c).Unitize()
8
9 # D represents the distance from the world origin (0,0,0)
10 # traveling exactly along the normal vector.
11 self.Distance = d
Distance (D)
1.50
1 min read1 page

FromNormal():

The most direct way to create a plane is by specifying its Origin point and the direction it should face (the Normal vector).
python
1class Plane:
2 @classmethod
3 def FromNormal(cls, origin: 'Point3d', normal: 'Vector3d') -> 'Plane':
4 """Constructs a plane from an origin point and a normal vector."""
5 return cls(origin, normal)
Tilt Normal X
0.00
Tilt Normal Z
0.00

From3Points():

Three non-collinear points perfectly define a flat surface. We use the Cross Product of the vectors between the points to find the plane's Normal.
python
1class Plane:
2 @classmethod
3 def From3Points(cls, a: 'Point3d', b: 'Point3d', c: 'Point3d') -> 'Plane':
4 """Constructs a plane passing through three points."""
5 # 1. Define the origin as the first point
6 origin = a
7
8 # 2. Create two vectors on the plane
9 vec1 = b - a
10 vec2 = c - a
11
12 # 3. The Cross Product gives us the perpendicular Normal!
13 normal = Vector3d.CrossProduct(vec1, vec2)
14
15 return cls(origin, normal)
Move Point C (Z)
-1.50
2 min read1 page

PointAt(U, V):

A plane is a 2D coordinate system. You can map local 2D parameters (U, V) into 3D world space coordinates (X, Y, Z) using the plane's basis vectors.
python
1class Plane:
2 def PointAt(self, u: float, v: float) -> 'Point3d':
3 """Evaluates a 2D (U, V) coordinate to a 3D World Point."""
4 # 1. Start at the Origin
5 point = self.Origin
6
7 # 2. Move along the X-Axis by 'U' distance
8 point = point + (self.XAxis * u)
9
10 # 3. Move along the Y-Axis by 'V' distance
11 point = point + (self.YAxis * v)
12
13 return point
Parameter U
1.00
Parameter V
1.50
2 min read1 page

ClosestPoint(Pt):

Finds the point on the plane that is closest to a test point in 3D space. This is equivalent to casting a shadow straight down (Projection) along the plane's Normal vector.
python
1class Plane:
2 def ClosestPoint(self, test_point: 'Point3d') -> 'Point3d':
3 """Projects a 3D point straight down onto the plane."""
4 # 1. Vector from origin to test point
5 vec = test_point - self.Origin
6
7 # 2. Distance along the normal (Dot Product)
8 dist = Vector3d.DotProduct(vec, self.Normal)
9
10 # 3. Move the test point BACK along the normal by that distance
11 return test_point - (self.Normal * dist)
Move Test X
-1.50
Move Test Z
2.00
1 min read1 page

DistanceTo(Pt):

Unlike lines, plane distance is Signed. If the point is in the direction of the Normal, the distance is positive. If it is behind the plane, the distance is negative.
python
1class Plane:
2 def DistanceTo(self, test_point: 'Point3d') -> float:
3 """Calculates the signed distance to a point."""
4 vec = test_point - self.Origin
5
6 # The Dot Product of the vector and the Normal gives
7 # the exact signed distance!
8 return Vector3d.DotProduct(vec, self.Normal)
Move Point Up/Down
2.00
1 min read1 page

Flip():

Flipping a plane reverses its Normal direction. This means "above" becomes "below", which affects signed distance calculations and mesh face rendering (normals).
python
1class Plane:
2 def Flip(self):
3 """Inverts the Normal direction of the plane."""
4 self.Normal.Reverse()
5
6 # To maintain the right-hand rule, one of the other
7 # axes (usually Y) is also reversed.
8 self._yAxis.Reverse()
Flip Plane (0/1)
1 min read1 page

Transform(Matrix):

Because a plane is just a coordinate system (Origin + 3 Axes), translating or rotating a plane is as simple as applying a Matrix4x4 transformation to those vectors.
python
1class Plane:
2 def Transform(self, xform: 'Matrix4x4'):
3 """Applies a Transformation Matrix to the plane."""
4 # Moving/Rotating a plane is exactly the same as
5 # multiplying its Origin and Basis Vectors by a matrix.
6 self.Origin.Transform(xform)
7 self.XAxis.Transform(xform)
8 self.YAxis.Transform(xform)
9 self.ZAxis.Transform(xform)
Translate X
2.00
Rotate Z
15.00
2 min read1 page

Intersection:

Because planes are infinite, any line that is not perfectly parallel to the plane will eventually intersect it at exactly one point.
python
1def LinePlaneIntersection(line: 'Line', plane: 'Plane') -> 'Point3d':
2 """Calculates the exact 3D point where a line pierces a plane."""
3
4 # 1. Dot product of line direction and plane normal
5 dot = Vector3d.DotProduct(line.Direction, plane.Normal)
6
7 # 2. If dot is 0, the line is parallel to the plane
8 if abs(dot) < 1e-6:
9 return None
10
11 # 3. Vector from line start to plane origin
12 vec = plane.Origin - line.StartPt
13
14 # 4. Calculate parameter 't' along the line
15 t = Vector3d.DotProduct(vec, plane.Normal) / dot
16
17 # 5. Get the point on the line at parameter 't'
18 return line.PointAt(t)
Move Line X
-3.00
Tilt Line
26.00
2 min read1 page

Plane-Plane Intersection:

When two non-parallel infinite planes intersect, they form an infinite Line. This operation is the foundational math behind cutting meshes and solid modeling (B-Reps).
python
1import math
2
3def plane_plane_intersection(plane_a: Plane, plane_b: Plane):
4 # Intersection line direction is cross product of normal vectors
5 dir_vec = plane_a.normal.cross(plane_b.normal)
6 if dir_vec.length_squared() < 0.0001:
7 return None # Parallel planes
8
9 dir_vec = dir_vec.normalized()
10 nA, nB = plane_a.normal, plane_b.normal
11 det = nA.length_squared() * nB.length_squared() - (nA.dot(nB))**2
12
13 if abs(det) < 1e-9:
14 return None
15
16 # Solve for the point on the intersection line closest to the origin
17 c1 = (plane_a.constant * nB.length_squared() - plane_b.constant * nA.dot(nB)) / det
18 c2 = (plane_b.constant * nA.length_squared() - plane_a.constant * nA.dot(nB)) / det
19 point = nA.multiply(-c1).add(nB.multiply(-c2))
20
21 return point, dir_vec
Tilt Plane B
15.00
Move Plane B (Y)
1.60
2 min read1 page

Orient (Plane-Plane):

Transforms geometry from the coordinate system of one plane (Plane A) directly into the coordinate system of another (Plane B).
python
1def orient_plane_to_plane(pt: Point3d, plane_from: Plane, plane_to: Plane) -> Point3d:
2 """Remaps a point from its relative position in plane_from to the same relative position in plane_to."""
3
4 # Method 1: Change basis to local space of plane_from, then map back using plane_to
5 xform_from = Transform.ChangeBasis(Plane.WorldXY, plane_from)
6 xform_to = Transform.ChangeBasis(plane_to, Plane.WorldXY)
7
8 pt_local = pt.Clone()
9 pt_local.Transform(xform_from)
10
11 pt_mapped = pt_local.Clone()
12 pt_mapped.Transform(xform_to)
13 return pt_mapped
14
15# Method 2: Direct plane-to-plane transformation matrix
16# xform_direct = Transform.PlaneToPlane(plane_from, plane_to)
17# pt_mapped = pt.Clone()
18# pt_mapped.Transform(xform_direct)
Plane-to-plane orientation maintains the exact relative local offsets. A point positioned at (dx, dy, dz) relative to Plane A is mapped to (dx, dy, dz) relative to Plane B, regardless of their position or tilt in 3D space.
Local Offset X
1.50
Local Offset Y
1.50
Local Offset Z
1.00