Initializing 3D Canvas...

The Sphere

1 min read•1 page

Perfect Symmetry

A Sphere is the set of all points in 3D space that are at a fixed distance (the radius) from a single point (the center). In the world of computational geometry, the sphere is the ultimate symbol of symmetry and efficiency.

Unlike a Mesh, which is an approximation made of flat faces, a mathematical Sphere is infinitely smooth.

Implicit vs. Explicit: A Mesh Sphere is explicit(made of points). A Mathematical Sphere is implicit(defined by x² + y² + z² = r²). Implicit geometry never loses precision.
Radius
2.00
1 min read•1 page

Data Structure

Because of its mathematical perfection, a Sphere requires almost no memory. To define a sphere in a CAD system, you only need:

  1. Center: A Point3d.
  2. Radius: A single double (floating point number).
python
1class Sphere:
2 """
3 Represents a mathematical sphere.
4 """
5 def __init__(self, center: Point3d, radius: float):
6 self.Center = center
7 self.Radius = radius

PointAt(u, v):

Maps spherical coordinates — Azimuth/Longitude (U) and Polar Angle/Colatitude (V) — to a 3D point on the sphere.
python
1def PointAt(self, u_degrees: float, v_degrees: float) -> Point3d:
2 """
3 Maps azimuth/longitude u (0°..360°) and polar angle/colatitude v (0°..180°)
4 to a 3D point on the sphere surface. (Note: latitude = 90° - v).
5 """
6 u_rad = math.radians(u_degrees)
7 v_rad = math.radians(v_degrees)
8 x = self.Radius * math.sin(v_rad) * math.cos(u_rad)
9 y = self.Radius * math.sin(v_rad) * math.sin(u_rad)
10 z = self.Radius * math.cos(v_rad)
11 return Point3d(x + self.Center.X, y + self.Center.Y, z + self.Center.Z)
While a Sphere is mathematically perfect, rendering engines still need to "unwrap" it to apply textures. In standard spherical coordinates, U (0° to 360°) sweeps around the equator as Azimuth / Longitude, while V (0° to 180°) sweeps from the North Pole (+Z) to the South Pole (-Z) as the Polar Angle (Colatitude), related to geographic latitude by Latitude = 90° - V.
The Singularities: At the exact top (V = 0°) and bottom (V = 180°) poles, all longitudinal lines converge to a single point.
Azimuth / Longitude (U°)
45.00
Polar / Colatitude (V°)
45.00
1 min read•1 page

Translate(vector):

Moving a sphere is computationally trivial — you only need to add a translation vector to its Center point.

python
1def Translate(self, vector: 'Vector3d'):
2 """Moving a sphere only requires moving its Center point."""
3 self.Center += vector
Move X
2.00
Move Y
1.00
1 min read•1 page

Scale(factor):

Scaling a sphere is mathematically elegant — you simply multiply theRadius by a scalar factor.
python
1def Scale(self, factor: float):
2 """Scaling a sphere is simply multiplying its Radius."""
3 self.Radius *= factor
Scale Factor
1.50
2 min read•1 page

Rotate(axis, angle):

A mathematical sphere is rotationally invariant around its own center: spinning it in place leaves its Center and Radius unchanged, rotating only its local UV frame.
python
1class Sphere:
2 def Rotate(self, angle_radians: float, axis: Vector3d, pivot: Point3d):
3 """
4 Rotates the sphere around a pivot axis.
5 If pivot == self.Center, the sphere's position is unchanged,
6 and only its local UV orientation frame rotates.
7 """
8 self.Center = RotatePointAroundAxis(self.Center, angle_radians, axis, pivot)
9 self.EquatorialPlane.Rotate(angle_radians, axis, self.Center)
In 3D modeling, rotating a sphere around its center only affects its UV texture seam or local coordinate axes. Rotating it around an external pivot orbits its Center point along a circular arc.
Rotation (°)
45.00
1 min read•1 page

Volume() & Area():

A sphere has two key analytical properties computable from the radius alone — no numerical integration needed. Volume is (4/3)πr³ and surface area is 4πr². These closed-form formulas are exact, unlike mesh-based approximations.
python
1import math
2
3class Sphere:
4 def Volume(self) -> float:
5 """Computes exact analytical enclosed volume of the sphere."""
6 return (4.0 / 3.0) * math.pi * (self.Radius ** 3)
7
8 def SurfaceArea(self) -> float:
9 """Computes exact analytical surface area of the sphere."""
10 return 4.0 * math.pi * (self.Radius ** 2)
Radius
2.00
3 min read•1 page

Intersection:

Sphere intersections (like Ray-Sphere) are mathematically beautiful because they can be solved perfectly using the standard quadratic formula, avoiding the need for complex polygon meshes. This makes spheres incredibly efficient for raytracing.
python
1def RaySphereIntersection(ray: 'Ray3d', sphere: 'Sphere') -> list['Point3d']:
2 """Finds intersection points between a ray and a sphere."""
3
4 # Solved using the quadratic formula: at^2 + bt + c = 0
5 # where t is the distance along the ray
6
7 L = ray.Position - sphere.Center
8 a = Vector3d.DotProduct(ray.Direction, ray.Direction)
9 b = 2.0 * Vector3d.DotProduct(ray.Direction, L)
10 c = Vector3d.DotProduct(L, L) - (sphere.Radius ** 2)
11
12 discriminant = b*b - 4*a*c
13
14 if discriminant < 0:
15 return [] # No intersection
16 elif discriminant == 0:
17 t = -b / (2*a)
18 return [ray.PointAt(t)] # One hit (tangent)
19 else:
20 t1 = (-b + math.sqrt(discriminant)) / (2*a)
21 t2 = (-b - math.sqrt(discriminant)) / (2*a)
22 return [ray.PointAt(t1), ray.PointAt(t2)] # Two hits
Move Ray X
0.00
4 min read•1 page

SphereSphere(a, b):

Two overlapping spheres intersect along a circle — the boundary where their volumes cross. The position and radius of this circle depends on the radii of both spheres and the distance between their centers. This is used in wave interference simulations, dome structural overlap analysis, and computational biology (atom packing).
python
1def SphereSphereIntersect(a: Sphere, b: Sphere) -> Circle:
2 """Calculates the circle of intersection between two spheres."""
3 # Vector from center A to center B
4 dx = b.Center.X - a.Center.X
5 dy = b.Center.Y - a.Center.Y
6 dz = b.Center.Z - a.Center.Z
7 d = math.sqrt(dx**2 + dy**2 + dz**2)
8
9 # Check for no intersection
10 if d > (a.Radius + b.Radius) or d < abs(a.Radius - b.Radius) or d == 0:
11 return None
12
13 # Distance from center A to the circle plane
14 x = (d**2 - b.Radius**2 + a.Radius**2) / (2 * d)
15
16 # Radius of the intersection circle
17 circle_radius = math.sqrt(a.Radius**2 - x**2)
18
19 # Center of the intersection circle
20 cx = a.Center.X + (dx / d) * x
21 cy = a.Center.Y + (dy / d) * x
22 cz = a.Center.Z + (dz / d) * x
23 circle_center = Point3d(cx, cy, cz)
24
25 # Normal of the circle's plane
26 normal = Vector3d(dx/d, dy/d, dz/d)
27
28 return Circle(circle_center, normal, circle_radius)
Center Distance
2.50
1 min read•1 page

Contains:

Checking if a point is inside a sphere is as simple as calculating the distance from the point to the sphere's center, and checking if that distance is less than the sphere's radius.
python
1def SphereContains(sphere: 'Sphere', pt: 'Point3d', strict: bool) -> bool:
2 """Checks if a point is inside a sphere."""
3
4 # Calculate the distance from the point to the sphere's center
5 dist = pt.DistanceTo(sphere.Center)
6
7 # Compare with radius
8 if strict:
9 return dist < sphere.Radius
10 else:
11 return dist <= sphere.Radius
Point X
1.50
Point Y
1.00
2 min read•1 page

NormalAt(u, v):

Calculates the outward unit normal vector at spherical coordinates (U, V) — where U is Azimuth/Longitude and V is Polar Angle/Colatitude.
python
1def NormalAt(self, u_degrees: float, v_degrees: float) -> Vector3d:
2 """
3 Returns the unit outward normal vector at azimuth/longitude u (0°..360°)
4 and polar angle/colatitude v (0°..180°).
5 """
6 u_rad = math.radians(u_degrees)
7 v_rad = math.radians(v_degrees)
8 x = math.sin(v_rad) * math.cos(u_rad)
9 y = math.sin(v_rad) * math.sin(u_rad)
10 z = math.cos(v_rad)
11
12 # The normal of a sphere is the unit vector from the center to the surface point
13 return Vector3d(x, y, z)
Since a sphere curves uniformly in all directions, the normal vector at any surface point always points straight outward along the ray from the sphere's center: N = (P - Center) / Radius.
Azimuth / Longitude (U°)
60.00
Polar / Colatitude (V°)
45.00
2 min read•1 page

Tangent Plane:

Constructs a mathematically flat plane that touches the curved sphere surface at spherical coordinates (U, V), where U is Azimuth/Longitude and V is Polar Angle/Colatitude.
python
1import math
2
3# Consistent spherical parametrization:
4# u = azimuth / longitude (0° to 360°)
5# v = polar angle / colatitude (0° to 180°, where latitude = 90° - v)
6
7def GetTangentPlane(sphere: Sphere, u_degrees: float, v_degrees: float) -> Plane:
8 """Returns the tangent plane at spherical coordinates (u, v) on the sphere."""
9 pt = sphere.PointAt(u_degrees, v_degrees)
10 normal = sphere.NormalAt(u_degrees, v_degrees)
11
12 # Construct a local plane at pt with its Z-axis aligned to the outward normal
13 return Plane(pt, normal)
A "Tangent Plane" is the flat approximation of a curved surface at a specific location. It acts as a local coordinate frame sitting directly on the surface, with its tangent X and Y axes lying in the plane and its Z-axis pointing straight out along the surface normal.
Azimuth / Longitude (U°)
45.00
Polar / Colatitude (V°)
60.00
2 min read•1 page

Great Circle:

The shortest path between two points on the surface of a sphere.
python
1def CreateGreatCircle(sphere: Sphere, ptA: Point3d, ptB: Point3d) -> Circle:
2 """Creates the great circle passing through two points on a sphere."""
3
4 # A Great Circle is created by slicing the sphere with a plane
5 # that passes through the sphere's center and the two target points.
6
7 # Plane through 3 points: Center, A, B
8 plane = Plane(sphere.Center, ptA, ptB)
9
10 # The great circle has the exact same radius as the sphere
11 great_circle = Circle(plane, sphere.Radius)
12
13 return great_circle
If you draw a straight 3D line between two cities on Earth, the line goes underground through the planet's crust. To travel on the surface, you must follow a curved path. The shortest possible curved path is called a "Geodesic" or "Great Circle". A Great Circle is formed by slicing the sphere with a plane that passes directly through the sphere's absolute center. This geometry is the basis for global flight paths, dome construction, and geodesic grid generation.
Move Destination
45.00
1 min read•1 page

ClosestPoint:

Finding the point on a sphere that is closest to an external point is mathematically elegant. You create a vector from the sphere's center to the test point, Unitize (normalize) it to length 1.0, and then scale it by the sphere's radius.
python
1def ClosestPoint(sphere: Sphere, test_pt: Point3d) -> Point3d:
2 """Projects a point onto the sphere boundary."""
3 # 1. Get direction from center
4 dir = test_pt - sphere.Center
5 if dir.Length < 1e-6:
6 dir = Vector3d(1.0, 0.0, 0.0)
7 # 2. Force length to match Radius
8 dir.Unitize()
9 return sphere.Center + (dir * sphere.Radius)
Search Pt X
4.00
Search Pt Y
4.00
Radius
2.00
2 min read•1 page

DistanceTo(point):

Calculates the shortest distance from an external point to the surface of the sphere.
python
1def DistanceTo(self, pt: Point3d) -> float:
2 """Calculates the shortest distance from a point to the surface of the sphere."""
3 # Calculate distance from the test point to the center of the sphere
4 dist_to_center = self.Center.DistanceTo(pt)
5
6 # Subtract the radius. If the point is inside, this will be negative,
7 # so we return max(0, distance) if we only want exterior distance.
8 return max(0.0, dist_to_center - self.Radius)
This is highly efficient because we only need to measure the distance to the center, and then subtract the sphere's radius.
Point X
3.00
Point Y
2.00
Radius
2.00
2 min read•1 page

Plane Intersection:

When an infinite plane slices through a sphere, the intersection is always a circle (or a single point if it's perfectly tangent). We can find the center of this circle by projecting the sphere's center onto the plane, and compute its radius using the Pythagorean theorem.
python
1def PlaneSphereIntersection(sphere: 'Sphere', plane: 'Plane') -> tuple[bool, 'Circle']:
2 """Finds the circle of intersection between a sphere and a plane."""
3 # Distance from sphere center to plane
4 # Assuming plane is defined by an Origin and Normal
5 vector_to_center = sphere.Center - plane.Origin
6 dist = Vector3d.DotProduct(vector_to_center, plane.Normal)
7
8 if abs(dist) > sphere.Radius:
9 return False, None # No intersection
10
11 # Radius of the resulting intersection circle
12 circle_radius = math.sqrt(sphere.Radius**2 - dist**2)
13
14 # Center of the intersection circle
15 circle_center = sphere.Center - (plane.Normal * dist)
16
17 return True, Circle(Plane(circle_center, plane.Normal), circle_radius)
Move Plane
0.50
2 min read•1 page

Box Intersection:

To check if a sphere intersects a bounding box, we first find the closest point on the box to the sphere's center. If the distance from the sphere's center to this closest point is less than or equal to the sphere's radius, they intersect.
python
1def SphereIntersectsBox(sphere: 'Sphere', box_min: Point3d, box_max: Point3d) -> bool:
2 """Checks if a sphere intersects an AABB by finding the closest point on the box to the sphere."""
3 # Find closest point on box to sphere center
4 closest_x = max(box_min.X, min(sphere.Center.X, box_max.X))
5 closest_y = max(box_min.Y, min(sphere.Center.Y, box_max.Y))
6 closest_z = max(box_min.Z, min(sphere.Center.Z, box_max.Z))
7
8 # Check if distance to closest point is within radius
9 closest_point = Point3d(closest_x, closest_y, closest_z)
10 distance = sphere.Center.DistanceTo(closest_point)
11
12 return distance <= sphere.Radius
Move Sphere X
0.00
Move Sphere Y
2.50
1 min read•1 page

Bounding Box Extraction:

Computing the AABB of a sphere is computationally trivial. Since a sphere's surface is equidistant from its center in all directions, its bounding box is just a cube formed by subtracting and adding the radius to the center coordinates.
python
1def SphereBoundingBox(sphere: 'Sphere') -> 'BoundingBox':
2 """Computes the Axis-Aligned Bounding Box (AABB) of a sphere."""
3 # A sphere's AABB is perfectly symmetric around its center
4 min_pt = Point3d(sphere.Center.X - sphere.Radius,
5 sphere.Center.Y - sphere.Radius,
6 sphere.Center.Z - sphere.Radius)
7
8 max_pt = Point3d(sphere.Center.X + sphere.Radius,
9 sphere.Center.Y + sphere.Radius,
10 sphere.Center.Z + sphere.Radius)
11
12 return BoundingBox(min_pt, max_pt)
Change Radius
1.50
2 min read•1 page

BoundingSphere(box):

Creates the smallest possible sphere that completely encloses a given bounding box.
python
1def BoundingSphere(bbox: BoundingBox) -> Sphere:
2 """Creates a sphere that exactly bounds an Axis-Aligned Bounding Box."""
3 # The center of the sphere is the center of the bounding box
4 center = bbox.Center
5
6 # The radius is the distance from the center to any of the box's corners
7 radius = center.DistanceTo(bbox.Max)
8
9 return Sphere(center, radius)
Spheres are often used as early-rejection bounding volumes because checking intersection against a sphere is computationally cheaper than checking against a box.
Box Width
2.00
Box Depth
3.00
Box Height
1.50
3 min read•1 page

FitSphere(points):

Constructs a sphere that encompasses a collection of points.
python
1def FitSphere(pts: list[Point3d]) -> Sphere:
2 """Calculates a bounding sphere for a collection of points."""
3 # A simple bounding approach is taking the bounding box,
4 # finding its center, and setting the radius to the farthest point.
5
6 # 1. Find bounding box center
7 min_pt, max_pt = GetBoundingBox(pts)
8 center = Point3d(
9 (min_pt.X + max_pt.X) / 2,
10 (min_pt.Y + max_pt.Y) / 2,
11 (min_pt.Z + max_pt.Z) / 2
12 )
13
14 # 2. Find the farthest point from the center
15 max_dist = 0.0
16 for pt in pts:
17 dist = center.DistanceTo(pt)
18 if dist > max_dist:
19 max_dist = dist
20
21 return Sphere(center, max_dist)
There are multiple ways to fit a sphere. A fast approximation is finding the bounding box center and setting the radius to encompass the farthest point. A more mathematically rigorous approach solves the linear system for exactly 4 points, or uses Welzl's algorithm for the absolute minimum bounding sphere.
Spread
2.00

Related Concepts