The Plane
1 min read•1 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 read•1 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 = origin4 # The normal vector defines the "up" direction5 # and perfectly locks the plane's rotation6 self.Normal = normal.Unitize()
1 min read•1 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 system3 @property4 def XAxis(self) -> 'Vector3d':5 return self._xAxis67 @property8 def YAxis(self) -> 'Vector3d':9 return self._yAxis1011 @property12 def ZAxis(self) -> 'Vector3d':13 return self.Normal
2 min read•1 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 = 056 # A, B, C represent the Normal Vector!7 self.Normal = Vector3d(a, b, c).Unitize()89 # 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.501 min read•1 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 @classmethod3 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.00Tilt Normal Z
0.00From3Points():
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 @classmethod3 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 point6 origin = a78 # 2. Create two vectors on the plane9 vec1 = b - a10 vec2 = c - a1112 # 3. The Cross Product gives us the perpendicular Normal!13 normal = Vector3d.CrossProduct(vec1, vec2)1415 return cls(origin, normal)
Move Point C (Z)
-1.502 min read•1 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 Origin5 point = self.Origin67 # 2. Move along the X-Axis by 'U' distance8 point = point + (self.XAxis * u)910 # 3. Move along the Y-Axis by 'V' distance11 point = point + (self.YAxis * v)1213 return point
Parameter U
1.00Parameter V
1.502 min read•1 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 point5 vec = test_point - self.Origin67 # 2. Distance along the normal (Dot Product)8 dist = Vector3d.DotProduct(vec, self.Normal)910 # 3. Move the test point BACK along the normal by that distance11 return test_point - (self.Normal * dist)
Move Test X
-1.50Move Test Z
2.001 min read•1 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.Origin56 # The Dot Product of the vector and the Normal gives7 # the exact signed distance!8 return Vector3d.DotProduct(vec, self.Normal)
Move Point Up/Down
2.001 min read•1 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()56 # To maintain the right-hand rule, one of the other7 # axes (usually Y) is also reversed.8 self._yAxis.Reverse()
Flip Plane (0/1)
1 min read•1 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 as5 # 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.00Rotate Z
15.002 min read•1 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."""34 # 1. Dot product of line direction and plane normal5 dot = Vector3d.DotProduct(line.Direction, plane.Normal)67 # 2. If dot is 0, the line is parallel to the plane8 if abs(dot) < 1e-6:9 return None1011 # 3. Vector from line start to plane origin12 vec = plane.Origin - line.StartPt1314 # 4. Calculate parameter 't' along the line15 t = Vector3d.DotProduct(vec, plane.Normal) / dot1617 # 5. Get the point on the line at parameter 't'18 return line.PointAt(t)
Move Line X
-3.00Tilt Line
26.002 min read•1 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 math23def plane_plane_intersection(plane_a: Plane, plane_b: Plane):4 # Intersection line direction is cross product of normal vectors5 dir_vec = plane_a.normal.cross(plane_b.normal)6 if dir_vec.length_squared() < 0.0001:7 return None # Parallel planes89 dir_vec = dir_vec.normalized()10 nA, nB = plane_a.normal, plane_b.normal11 det = nA.length_squared() * nB.length_squared() - (nA.dot(nB))**21213 if abs(det) < 1e-9:14 return None1516 # Solve for the point on the intersection line closest to the origin17 c1 = (plane_a.constant * nB.length_squared() - plane_b.constant * nA.dot(nB)) / det18 c2 = (plane_b.constant * nA.length_squared() - plane_a.constant * nA.dot(nB)) / det19 point = nA.multiply(-c1).add(nB.multiply(-c2))2021 return point, dir_vec
Tilt Plane B
15.00Move Plane B (Y)
1.602 min read•1 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."""34 # Method 1: Change basis to local space of plane_from, then map back using plane_to5 xform_from = Transform.ChangeBasis(Plane.WorldXY, plane_from)6 xform_to = Transform.ChangeBasis(plane_to, Plane.WorldXY)78 pt_local = pt.Clone()9 pt_local.Transform(xform_from)1011 pt_mapped = pt_local.Clone()12 pt_mapped.Transform(xform_to)13 return pt_mapped1415# Method 2: Direct plane-to-plane transformation matrix16# 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.50Local Offset Y
1.50Local Offset Z
1.00