Geometry & 3D Vision
Homogeneous Coordinates
Representing a point by a vector with one extra coordinate, defined only up to scale, so that translations, perspective projections, and points at infinity can all be handled with matrix multiplication.
beginner
Homogeneous coordinates represent a point in the plane by three numbers instead of two, and a point in space by four instead of three, with the rule that multiplying all of them by the same non-zero factor gives the same point. This small change makes translation, rotation, scaling, and perspective projection all expressible as matrix multiplication, gives parallel lines a common point “at infinity”, and turns the line through two points and the intersection of two lines into single cross products. Camera models, image warps, and multiple view geometry in computer vision are almost always written in homogeneous coordinates.
Definition
The homogeneous coordinates of a 2D point are any vector with . A homogeneous vector with represents the Cartesian point ; a vector with represents a point at infinity, which has no Cartesian counterpart. The zero vector represents nothing. The same construction in any dimension represents a point of by an -vector defined up to scale (Hartley and Zisserman, 2004, §1.1 and §2.2).
Intuition
Think of the image plane as the plane inside a 3D space with coordinates . Every line through the origin of that space pierces the plane in exactly one point, unless it is parallel to the plane. Homogeneous coordinates identify a 2D point with the whole line through the origin, and any non-zero point on that line can stand for it. Dividing by slides back along the line to where it meets .
The lines through the origin that are parallel to the plane never meet it. They are the vectors , and they correspond to directions in the plane rather than positions. This is the sense in which parallel lines “meet at infinity”: two parallel lines share a direction, and in homogeneous coordinates that direction is a genuine point, , lying on both.
A camera works the same way. Every 3D point on a ray through the camera center projects to the same image point, so an image point naturally corresponds to a ray, known only up to scale, which is what a homogeneous vector is.
Formal Definition
Points, equivalence, and conversion
Two homogeneous vectors are equivalent, written , when for some . The set of equivalence classes of non-zero 3-vectors is the projective plane , described in projective geometry. Conversion in both directions is
Transformations as matrices
A translation by is not a linear map of , but it is a linear map of homogeneous vectors:
Rotations, similarities, and affine maps take the same form with a different upper-left block, and a general invertible matrix is a projective transformation, . The image warping article lists the translation, similarity, affine, and projective matrices. A sequence of transformations applied first , then , then is the single matrix .
Lines
A line is represented by the homogeneous 3-vector , also defined up to scale. A point lies on exactly when
From this incidence relation follow two results (Hartley and Zisserman, 2004, §2.2): the line through two points and the intersection of two lines are both cross products,
The two parallel lines and intersect at , the point at infinity in their common direction. All points at infinity satisfy , so they lie on one line, the line at infinity .
Three dimensions
A 3D point has homogeneous coordinates , and points with fourth coordinate zero form the plane at infinity. A rigid motion with rotation and translation is the matrix
and a general invertible matrix is a projective transformation of 3D space. A pinhole camera maps homogeneous 3D points to homogeneous image points with a matrix, ; the division by depth that perspective projection requires is exactly the final division by the third coordinate.
Properties
- Scale invariance. Every equation is homogeneous: and hold or fail regardless of the scale of the vectors. This is why a projective transformation has 8 degrees of freedom, not 9.
- Composition and inversion. Transformations compose by matrix product and invert by matrix inverse, so a chain of warps or coordinate changes collapses into one matrix.
- Duality. Points and lines in the plane are both homogeneous 3-vectors, and the incidence relation is symmetric in them, so every statement about points and lines has a dual with the roles exchanged.
- Uniform treatment of infinity. Points at infinity are ordinary vectors, so intersecting parallel lines or projecting a direction needs no special case.
Numerical notes
Homogeneous vectors are often normalized, either so that the last coordinate is 1 (only possible for finite points) or to unit norm (always possible, and better conditioned). A point whose last coordinate is close to zero relative to the others is far away or nearly at infinity: dividing by it amplifies noise, and code that converts back to Cartesian coordinates should test for it rather than divide blindly. Equations of the form are also sensitive to units: pixel coordinates in the hundreds next to a third coordinate of 1 make the problems solved in least-squares estimation badly conditioned, which is why Hartley and Zisserman recommend translating and scaling image coordinates before estimating a homography or other transformation (2004, §4.4).
History
Homogeneous coordinates are usually traced to August Ferdinand Möbius’s Der barycentrische Calcul (1827), which describes points by weights relative to a reference triangle; Julius Plücker, among others, developed them further in nineteenth-century analytic geometry. They later entered computer graphics and vision as the standard way to write transformations and perspective projection as matrices.
Examples
The code computes a line through two points, intersects it with another line, intersects two parallel lines, and builds a rotation about a point other than the origin as a single matrix: translate the point to the origin, rotate, and translate back.
import numpy as np
def to_h(p):
"""Cartesian (x, y) -> homogeneous (x, y, 1)."""
return np.array([p[0], p[1], 1.0])
def from_h(v, eps=1e-12):
"""Homogeneous (x, y, w) -> Cartesian (x/w, y/w); None for a point at infinity."""
return None if abs(v[2]) < eps else v[:2] / v[2]
# A line through two points is their cross product: l . x = 0 for both points.
p, q = to_h((0, 1)), to_h((2, 3))
l1 = np.cross(p, q)
print("line through (0,1) and (2,3):", l1, " check l.p, l.q =", l1 @ p, l1 @ q)
# The intersection of two lines is also a cross product.
l2 = np.cross(to_h((0, 4)), to_h((4, 0))) # the line x + y = 4
x = np.cross(l1, l2)
print("intersection (homogeneous):", x, "-> Cartesian:", from_h(x))
# Parallel lines y = x + 1 and y = x - 2 meet at a point with w = 0.
l3 = np.array([1.0, -1.0, 1.0]) # x - y + 1 = 0
l4 = np.array([1.0, -1.0, -2.0]) # x - y - 2 = 0
v = np.cross(l3, l4)
print("parallel lines meet at:", v, "-> Cartesian:", from_h(v), "(direction", v[:2] / np.linalg.norm(v[:2]), ")")
# Any homogeneous scale represents the same point.
print("scaled copy, same point:", from_h(-2.5 * x))
# Rotation by 90 degrees about the point c = (2, 1): translate, rotate, translate back.
def T(tx, ty):
return np.array([[1, 0, tx], [0, 1, ty], [0, 0, 1.0]])
def R(theta):
c, s = np.cos(theta), np.sin(theta)
return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1.0]])
M = T(2, 1) @ R(np.pi / 2) @ T(-2, -1) # applied right to left
print("composed matrix:\n", np.round(M, 6))
for pt in [(2, 1), (3, 1), (2, 3)]:
print(f" {pt} -> {np.round(from_h(M @ to_h(pt)), 6)}")
Output:
line through (0,1) and (2,3): [-2. 2. -2.] check l.p, l.q = 0.0 0.0
intersection (homogeneous): [-24. -40. -16.] -> Cartesian: [1.5 2.5]
parallel lines meet at: [3. 3. 0.] -> Cartesian: None (direction [0.70710678 0.70710678] )
scaled copy, same point: [1.5 2.5]
composed matrix:
[[ 0. -1. 3.]
[ 1. 0. -1.]
[ 0. 0. 1.]]
(2, 1) -> [2. 1.]
(3, 1) -> [2. 2.]
(2, 3) -> [0. 1.]
The line is up to scale. Its intersection with comes out with an arbitrary scale, , and dividing by the last coordinate gives . The two parallel lines meet at , a point at infinity in their shared direction . The composed matrix leaves the center fixed and turns the other points by 90° around it.
The same pattern finds vanishing points in images. The image of the point at infinity of a family of parallel scene lines, such as the edges of a corridor or the rails of a track, is the vanishing point where their images converge; it is found by intersecting two of the image lines with a cross product, or, when there are more, as the least-squares null vector of the stacked line vectors. The projective geometry article discusses vanishing points and the horizon.
Common Misconceptions
- “The third coordinate is always 1.” Setting it to 1 is a choice of representative, convenient for finite points. After a projective transformation it is generally not 1, and points at infinity have it equal to 0. Forgetting to divide is a common bug.
- “Homogeneous coordinates are just a trick for translation.” Handling translation is the most visible benefit, but the deeper one is that perspective projection, which divides by depth, becomes linear up to scale, and that points at infinity become ordinary points.
- “ is the origin.” It is a direction, not a position: the point at infinity in direction . The origin is .
- “Normalizing to is always safe.” It fails for points at infinity and is unstable for points far away; normalize to unit length when such points can occur.
Where It Is Used
- Camera models. The pinhole camera model writes projection as , with the intrinsic matrix and the extrinsic rotation and translation described in camera parameters.
- Image warping. Parametric image warps are matrices acting on homogeneous pixel coordinates, composed by multiplication and inverted for backward mapping; the homography, which relates two views of a plane, is the general case.
- Multiple view geometry. Epipolar constraints, triangulation, and camera calibration are formulated as linear equations in homogeneous vectors (Hartley and Zisserman, 2004).
- Graphics pipelines. Rendering systems transform vertices with matrices, from object to world to camera coordinates and then through a perspective projection, followed by division by the fourth coordinate; Szeliski (2022, §2.1) presents 2D and 3D transformations in the same homogeneous form.
Related
- Projective Geometry
The geometry of properties that survive perspective projection, such as straightness, incidence, and the cross-ratio, which underlies how computer vision models cameras and relates images.
- Pinhole Camera Model
The ideal camera in which every scene point projects through a single center onto an image plane, giving the perspective projection x = fX/Z, y = fY/Z.
- Camera Intrinsic and Extrinsic Parameters
The parameters of the pinhole camera matrix P = K[R | t], split into intrinsics K, which map camera coordinates to pixels, and extrinsics R and t, which place the camera in the world.
- Image Warping
Transforming the geometry of an image by a coordinate mapping, usually computed by sampling the input image at the inverse-mapped position of every output pixel.