The Point
The Infinite Zero
The fundamental building block of all geometry, yet paradoxically, it has no physical dimensions. It has no length, no width, and no depth. It is purely a coordinate, an absolute location in space.
The Relationship to Vectors
A vector is a collection of numbers representing pure direction and magnitude [X, Y, Z]. It floats freely without location.
A Point, geometrically, can be thought of as a Vector that is strictly anchored to the Origin (0,0,0). When you evaluate the coordinates (X, Y, Z), you are essentially measuring the vector required to travel from the Origin to that absolute location.
The Pure Data Structure
At its core, a point is stored in memory as an ordered list of three double-precision floating-point numbers (X, Y, Z).
1class Point3d:2 def __init__(self, x: float, y: float, z: float):3 self.X = float(x)4 self.Y = float(y)5 self.Z = float(z)67 def __str__(self):8 return f"Point3d({self.X}, {self.Y}, {self.Z})"910 @classmethod11 def Origin(cls):12 """Gets the point at (0,0,0)."""13 return cls(0.0, 0.0, 0.0)
Point3d~=Vector3d
The math behind it is exactly the same.
DistanceTo(Point3d):
1import math23class Point3d:4 def DistanceTo(self, other: 'Point3d') -> float:5 """Returns the distance between two points."""6 dx, dy, dz = other.X - self.X, other.Y - self.Y, other.Z - self.Z7 return math.sqrt(dx**2 + dy**2 + dz**2)
VectorTo(Point3d):
DistanceToSquared(Point3d):
1import math23class Point3d:4 def DistanceTo(self, other: 'Point3d') -> float:5 # EXPENSIVE: math.sqrt is a heavy operation6 dx = self.X - other.X7 dy = self.Y - other.Y8 dz = self.Z - other.Z9 return math.sqrt(dx**2 + dy**2 + dz**2)1011 def DistanceToSquared(self, other: 'Point3d') -> float:12 # CHEAP: No square root required13 dx = self.X - other.X14 dy = self.Y - other.Y15 dz = self.Z - other.Z16 return dx**2 + dy**2 + dz**2
Square roots (math.sqrt) are computationally expensive. When writing algorithms like `ClosestPoint` that compare thousands of distances to find the smallest one, we don't need the actual distance, we just need to know which one is relatively smaller.
If A < B, then A² < B². Using DistanceToSquared inside loops saves significant processing time.
Subtract(Point3d):
1class Point3d:2 def Subtract(self, other: 'Point3d') -> 'Vector3d':3 """Subtracting a point from another point yields a Vector."""4 # Note that the result is a Vector3d, not a Point3d5 return Vector3d(6 self.X - other.X,7 self.Y - other.Y,8 self.Z - other.Z9 )
Interpolate(Point3d, float):
1class Point3d:2 def Interpolate(self, other: 'Point3d', t: float) -> 'Point3d':3 """Finds a point between self and other based on parameter t."""4 # t = 0.0 returns self5 # t = 1.0 returns other6 # t = 0.5 returns the midpoint78 return Point3d(9 self.X + (other.X - self.X) * t,10 self.Y + (other.Y - self.Y) * t,11 self.Z + (other.Z - self.Z) * t12 )
Move(Vector3d):
1class Point3d:2 def Move(self, vector: 'Vector3d') -> 'Point3d':3 """Translates the point by adding a vector."""4 return Point3d(self.X + vector.X, self.Y + vector.Y, self.Z + vector.Z)
Scale(float):
2.0 doubles the length of the vector connecting the Origin to the Point.1class Point3d:2 def Scale(self, scale_factor: float) -> 'Point3d':3 """Scales the point relative to the origin."""4 return Point3d(self.X * scale_factor, self.Y * scale_factor, self.Z * scale_factor)
Rotate(Axis3d, float):
1import math23class Point3d:4 def Rotate(self, axis: 'Vector3d', angle_degrees: float) -> 'Point3d':5 """Rotates the point around the given axis."""6 angle_rad = math.radians(angle_degrees)7 cos_a = math.cos(angle_rad)8 sin_a = math.sin(angle_rad)910 ux, uy, uz = axis.X, axis.Y, axis.Z1112 # Rodrigues' rotation formula applied to the position vector13 x_new = self.X * (cos_a + ux*ux*(1-cos_a)) + self.Y * (ux*uy*(1-cos_a) - uz*sin_a) + self.Z * (ux*uz*(1-cos_a) + uy*sin_a)14 y_new = self.X * (uy*ux*(1-cos_a) + uz*sin_a) + self.Y * (cos_a + uy*uy*(1-cos_a)) + self.Z * (uy*uz*(1-cos_a) - ux*sin_a)15 z_new = self.X * (uz*ux*(1-cos_a) - uy*sin_a) + self.Y * (uz*uy*(1-cos_a) + ux*sin_a) + self.Z * (cos_a + uz*uz*(1-cos_a))1617 return Point3d(x_new, y_new, z_new)
FindClosestPoint(Point3d, list[Point3d]):
1def FindClosestPoint(test_pt: Point3d, cloud: list[Point3d]) -> Point3d:2 """Brute force search for the closest point."""3 closest = cloud[0]4 min_dist = test_pt.DistanceTo(closest)56 for pt in cloud:7 d = test_pt.DistanceTo(pt)8 if d < min_dist:9 min_dist = d10 closest = pt11 return closest
Centroid(list[Point3d]):
1def Centroid(points: list[Point3d]) -> Point3d:2 """Calculates the arithmetic average of a list of points."""3 n = len(points)4 if n == 0:5 return None67 cx = sum(p.X for p in points) / n8 cy = sum(p.Y for p in points) / n9 cz = sum(p.Z for p in points) / n1011 return Point3d(cx, cy, cz)
WeightedCenter(list[Point3d], list[float]):
1def WeightedCenter(points: list[Point3d], weights: list[float]) -> Point3d:2 """Calculates the center of mass based on point weights."""3 total_weight = sum(weights)45 if total_weight == 0:6 return None78 cx = sum(p.X * w for p, w in zip(points, weights)) / total_weight9 cy = sum(p.Y * w for p, w in zip(points, weights)) / total_weight10 cz = sum(p.Z * w for p, w in zip(points, weights)) / total_weight1112 return Point3d(cx, cy, cz)
DistanceToPlane(Plane):
1def DistanceToPlane(point: Point3d, plane_origin: Point3d, plane_normal: Vector3d) -> float:2 """Calculates the signed distance from a point to a plane."""3 # Vector from plane origin to the test point4 v = point - plane_origin56 # Project the vector onto the plane normal7 # Ensure normal is unitized8 n = Vector3d(plane_normal)9 n.Unitize()1011 # Signed distance is the dot product12 return v * n
ProjectTo(Plane):
1def ProjectToPlane(point: Point3d, plane_origin: Point3d, plane_normal: Vector3d) -> Point3d:2 # Get signed distance to plane3 d = DistanceToPlane(point, plane_origin, plane_normal)45 # Shift point back along normal6 return point - plane_normal * d
IsOnPlane(Plane):
1def IsOnPlane(point: Point3d, plane_origin: Point3d, plane_normal: Vector3d, tolerance: float = 1e-6) -> bool:2 """Checks if a point lies on a plane within a tolerance."""3 dist = DistanceToPlane(point, plane_origin, plane_normal)4 return abs(dist) <= tolerance
Transform(Transform):
1# 1. Create a matrix (e.g. translation)2xform = Transform.Translation(1.5, 2.0, 3.0)34# 2. Apply it to the point (modifies in place)5pt.Transform(xform)
Translate, Scale, and Rotate are convenient, under the hood they all generate a 4x4 Matrix and pass it to this master Transform method.3 Applications
A single point can act as an attractor or repeller in a generative system. By calculating the distance vector between the attractor point and a grid of other objects, we can scale or move the objects based on their proximity, producing organic, non-uniform distributions.
1# Attractor Logic2for obj_pt in grid:3 dist = attractor.DistanceTo(obj_pt)4 if dist < threshold:5 # Scale based on proximity6 obj.Scale(1.0 / dist)