upgrade
upgrade

📐Computational Geometry

Fundamental Geometric Primitives

Study smarter with Fiveable

Get study guides, practice questions, and cheatsheets for all your subjects. Join 500,000+ students with a 96% pass rate.

Get Started

Why This Matters

Every algorithm in computational geometry—from collision detection to mesh generation to spatial indexing—builds on a small set of fundamental primitives. When you're implementing a convex hull algorithm, designing a ray tracer, or solving intersection problems, you're really manipulating points, lines, and polygons in precise mathematical ways. Understanding these primitives isn't just about definitions; it's about knowing how they're represented, what operations they support, and when to use each one.

You're being tested on your ability to choose the right primitive for a given problem, convert between representations efficiently, and understand the mathematical properties that make certain algorithms work. Don't just memorize that a line segment has two endpoints—know why parametric representation makes intersection tests elegant, why convex polygons simplify so many algorithms, and how vectors enable the transformations that power computer graphics. Master the primitives, and the algorithms will follow.


Zero-Dimensional and Directional Primitives

These primitives represent positions and directions—the atomic units from which all other geometric objects are constructed. Points define "where," while vectors define "which way" and "how far."

Points

  • Represented as coordinate tuples P=(x,y)P = (x, y) in 2D or P=(x,y,z)P = (x, y, z) in 3D—the foundation for every other primitive
  • Dimensionless by definition—no area, volume, or extent; purely a location in space
  • Homogeneous coordinates (x,y,w)(x, y, w) allow unified treatment of transformations including translation

Vectors

  • Encode magnitude and direction as v=(vx,vy)\vec{v} = (v_x, v_y), distinct from points because they represent displacement, not position
  • Support critical operations—dot product ab\vec{a} \cdot \vec{b} tests perpendicularity; cross product a×b\vec{a} \times \vec{b} computes area and orientation
  • Essential for transformations—rotation, scaling, and translation all operate through vector arithmetic

Compare: Points vs. Vectors—both are coordinate tuples, but points represent locations while vectors represent displacements. In code, the distinction matters: adding two points is meaningless, but subtracting them yields a vector. If an interview asks about geometric transformations, vectors are your answer.


One-Dimensional Linear Primitives

Lines and their bounded variants form the backbone of intersection algorithms, visibility computations, and geometric queries. The key distinction is extent: infinite, semi-infinite, or finite.

Lines

  • Multiple representations—implicit form ax+by+c=0ax + by + c = 0, parametric form P(t)=P0+tdP(t) = P_0 + t\vec{d}, or slope-intercept y=mx+by = mx + b
  • Extend infinitely in both directions—useful for theoretical constructs but rarely stored directly in practical applications
  • Signed distance from point to line enables half-plane classification, critical for convex hull and polygon algorithms

Rays

  • Semi-infinite—defined by origin point OO and direction d\vec{d}, extending as R(t)=O+tdR(t) = O + t\vec{d} for t0t \geq 0
  • Fundamental to ray casting and ray tracing—every visibility query, shadow test, and intersection computation uses rays
  • Parameterized queries return tt values, making it easy to find closest intersections or sort hit points

Line Segments

  • Bounded by two endpoints P0P_0 and P1P_1, with parametric form S(t)=P0+t(P1P0)S(t) = P_0 + t(P_1 - P_0) for t[0,1]t \in [0, 1]
  • Length computed via Euclidean distanceP1P0=(x1x0)2+(y1y0)2\|P_1 - P_0\| = \sqrt{(x_1-x_0)^2 + (y_1-y_0)^2}
  • Intersection testing requires checking both collinearity and parameter bounds—a common source of implementation bugs

Compare: Rays vs. Line Segments—both are bounded versions of lines, but rays extend infinitely in one direction (t0t \geq 0) while segments are finite (t[0,1]t \in [0,1]). Ray-object intersection returns "does it hit and where," while segment intersection asks "do these two finite edges cross."


Two-Dimensional Surface Primitives

Planes define the 2D surfaces embedded in 3D space that partition regions and enable surface computations. In 2D problems, lines play the analogous role.

Planes

  • Defined by normal vector and offset—implicit form nP+d=0\vec{n} \cdot P + d = 0 or equivalently ax+by+cz+d=0ax + by + cz + d = 0
  • Three non-collinear points determine a unique plane—compute normal via cross product n=(P1P0)×(P2P0)\vec{n} = (P_1 - P_0) \times (P_2 - P_0)
  • Half-space classification uses sign of nP+d\vec{n} \cdot P + d to determine which side of the plane a point lies on

Compare: Lines (2D) vs. Planes (3D)—both partition space into half-spaces using signed distance. The implicit equation ax+by+c=0ax + by + c = 0 in 2D generalizes to ax+by+cz+d=0ax + by + cz + d = 0 in 3D. Algorithms like BSP trees work identically in both dimensions.


Polygonal Primitives

Polygons are the workhorses of computational geometry—they approximate curves, define regions, and form the basis of mesh representations. Convexity is the key property that determines algorithmic complexity.

Triangles

  • Simplest polygon—three vertices, three edges, always planar and always convex
  • Barycentric coordinates (u,v,w)(u, v, w) with u+v+w=1u + v + w = 1 enable point-in-triangle tests and smooth interpolation
  • Universally used in rendering—GPUs are optimized for triangles; any surface can be triangulated

Polygons

  • Ordered sequence of vertices {P0,P1,,Pn1}\{P_0, P_1, \ldots, P_{n-1}\} with edges connecting consecutive points
  • Convex vs. concave—convex polygons have all interior angles <180°< 180°; concave polygons require more complex algorithms
  • Area via shoelace formulaA=12i=0n1(xiyi+1xi+1yi)A = \frac{1}{2}|\sum_{i=0}^{n-1}(x_i y_{i+1} - x_{i+1} y_i)|, a signed value indicating winding order

Convex Hulls

  • Smallest convex polygon containing all input points—like stretching a rubber band around the point set
  • Computed by algorithms like Graham scan O(nlogn)O(n \log n), Jarvis march O(nh)O(nh), or QuickHull O(nlogn)O(n \log n) expected
  • Preprocessing step for many algorithms—simplifies collision detection, diameter computation, and spatial queries

Compare: Triangles vs. General Polygons—triangles are always convex and have constant-time point-in-polygon tests; general polygons require O(n)O(n) ray casting or winding number tests. When in doubt, triangulate: any simple polygon can be decomposed into n2n-2 triangles.


Curved Primitives

Circles represent the fundamental curved primitive, enabling smooth boundaries and distance-based queries. Most curved geometry in computational applications is approximated by polygons, but circles have special-case algorithms.

Circles

  • Defined by center CC and radius rr—implicit form (xcx)2+(ycy)2=r2(x - c_x)^2 + (y - c_y)^2 = r^2
  • Point containment is a simple distance check: PCr\|P - C\| \leq r for interior points
  • Circle-circle intersection determines collision detection; smallest enclosing circle solves facility location problems in O(n)O(n) expected time

Compare: Circles vs. Convex Polygons—both define convex regions, but circles have infinite symmetry while polygons have discrete vertices. Collision detection between circles is O(1)O(1); between convex polygons it's O(logn)O(\log n) with preprocessing. Use circles for bounding volumes when rotation invariance matters.


Quick Reference Table

ConceptBest Examples
Position representationPoints, Homogeneous coordinates
Direction and magnitudeVectors, Rays
Linear extentLines, Line segments, Rays
Space partitioningPlanes, Lines (2D), Half-spaces
Bounded regionsPolygons, Triangles, Circles
Convexity propertiesConvex hulls, Triangles, Circles
Parametric representationLine segments t[0,1]t \in [0,1], Rays t0t \geq 0
Implicit representationLines ax+by+c=0ax + by + c = 0, Planes, Circles

Self-Check Questions

  1. Representation choice: You need to test whether a point lies to the left or right of a directed line. Which representation of a line makes this easiest, and what mathematical operation do you use?

  2. Compare and contrast: Both rays and line segments are bounded versions of lines. Explain how their parametric representations differ and give one algorithm that specifically requires rays rather than segments.

  3. Convexity matters: Why do convex hull algorithms produce useful output even when the input is already a polygon? What property of the output guarantees simpler subsequent computations?

  4. Primitive selection: You're implementing a 2D physics engine and need to detect collisions between rotating objects. Compare the tradeoffs between using circles versus convex polygons as bounding shapes.

  5. Cross-primitive operations: Given three points AA, BB, and CC, describe how you would use vector operations to determine (a) whether they are collinear, and (b) if not, whether CC lies to the left or right of the directed line from AA to BB.