liveBook · Manning

Box product

As explained in Geometry for Programmers

A box product is the two-dimensional determinant-like product of vector components used to determine the relative orientation of planar vectors.

A box product is a determinant-based product of vectors. In N-dimensional space, it takes N vectors with N components and returns the determinant of the matrix they form. In two dimensions, it describes the signed area of the parallelogram spanned by two vectors: a positive or negative sign records orientation, while zero indicates degeneracy. section 9.5.2

For two-dimensional vectors, compute the product directly:

  • box((a1, b1), (a2, b2)) = a1b2 − a2b1. section 9.5.2 section 9.5.3
  • Use the sign to distinguish the vectors’ orientation and the magnitude to obtain parallelogram area. section 9.5.2
  • In higher dimensions, build the vectors into a square matrix and take its determinant; symbolic expressions quickly become unwieldy. section 9.5.2 section 9.5.3

Signed distance to a line

A 2D box product turns directly into a signed distance calculation. For a point (x, y) and line endpoints (x1, y1), (x2, y2), compute box2d(x−x1, y−y1, x2−x1, y2−y1) and divide by the endpoint distance. The result is the parallelogram’s signed area divided by its base length. This construction supports point-to-line and point-to-segment distances, including signed distance functions for rectangles. section 10.1.4

def dot2d(x1, y1, x2, y2):   #1
    return x1*x2 + y1*y2     #1
 
def box2d(x1, y1, x2, y2):   #2
    return x1*y2 - x2*y1     #2

A compact Python implementation defines the 2D dot product alongside box2d(x1, y1, x2, y2) = x1*y2 − x2*y1. section 10.1.4

How Geometry for Programmers covers it

How deep it goes
Explains the 2D formula and N-dimensional determinant generalization, then defers practical high-dimensional determinant computation.
Examples
Demonstrates 2D, 3D, and 4D determinant forms plus Python distance routines for lines, segments, and rectangles.
What it assumes
Assumes vectors, matrices, determinants, dot products, and basic geometry while deriving the 2D case concretely.
What you can do after
Apply it via Python or SymPy to compute signed 2D areas, determinants, line distances, segment distances, and rectangle distance fields.
How it connects
Connects determinants, cross products, triple products, dot products, projections, parallelograms, and signed distance functions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Geometry for Programmers. The section links point to the parts of the book it draws on.