liveBook · Manning

Inner product

As explained in Geometry for Programmers

The dot product is a scalar product of two vectors formed by summing the products of corresponding coordinates.

The dot product combines two vectors and returns one scalar number. For vectors a = (a1, a2, a3) and b = (b1, b2, b3), it is a · b = a1b1 + a2b2 + a3b3. For example, (2, 3, 4) · (5, 6, 7) = 56. The same coordinate-by-coordinate rule works in 2D and generalizes to N dimensions. section 9.2.1

Its useful geometric meaning comes from projection and angle. When one vector has length 1, its dot product with another vector is the length of that other vector projected onto it. More generally, the result is the two vector lengths multiplied by the cosine of the angle between them. This turns a small arithmetic operation into a test of how strongly two directions align. section 9.2.1 section 9.2.4

Figure 9.5 The trigonometric sense of the dot product
09-05

Use the projection diagram to connect the cosine term to the adjacent side of a right triangle: alignment preserves more of a vector’s length, while a right angle contributes none. section 9.2.1

Three directional cases make the sign easy to interpret:

  • Co-oriented vectors produce the maximal lighting coefficient, 1, when both directions are normalized. section 9.2.3
  • Orthogonal vectors have dot product 0, so one vector has no projection along the other. section 9.2.4
  • Counter-oriented vectors produce -1 when normalized; lighting can ignore values below 0. section 9.2.3

Lighting a surface

For each visible surface element, form a normalized vector toward the light and take its dot product with the surface normal. The result is a lighting coefficient: facing the light is brightest, a perpendicular surface receives zero light, and a surface facing away can be darkened by clamping negative values. This same scene-lighting picture is a practical mnemonic for remembering that the formula uses cosine. section 9.2.3 section 9.2.4

The dot product also expresses geometric constraints. To join an arc smoothly to a line segment, the vector from the arc center to the intersection point must be orthogonal to the segment direction. Writing their dot product as zero supplies the smoothness equation alongside the equations for the arc center and line intersection. section 5.3.2

Listing 5.2 Solution to an arc and line segment equation
x1, y1, dx1, dy1 = symbols('x1 y1 dx1 dy1')
x2, y2, dx2, dy2 = symbols('x2 y2 dx2 dy2')
r1 = symbols('r1')                         #1
  
ix, iy = symbols('ix iy')                  #2
 
ax1, ay1, t2 = symbols('ax1 ay1 t2')       #3
 
solutions = solve(
   [
    x1 - r1*dy1 - ax1,                     #4
    y1 + r1*dx1 - ay1,
    x2 + dx2 * t2 - ix,                    #5
    y2 + dy2 * t2 - iy,
    (ix-ax1)*dx2 + (iy-ay1)*dy2            #6
], (ax1, ay1, t2, ix, iy))

The SymPy system includes the dot-product-equals-zero constraint with equations for the arc center and line point, solving five variables for a smooth arc-and-segment piece. section 5.3.2

In SymPy’s 3D vector system, vectors are weighted sums of basis vectors in a coordinate system. Call a.dot(b), or use a & b, to compute their dot product. A compact 2D helper can simply return x1*x2 + y1*y2; it is useful for projecting a point onto a segment, including the normalized projection that decides whether the closest point lies before, within, or after the segment. section 9.2.2 section 10.1.4

How Geometry for Programmers covers it

How deep it goes
Defines coordinate and N-dimensional forms, derives projection and angle meaning, and implements SymPy and 2D uses without deriving broader vector-product theory.
Examples
Demonstrates coordinate multiplication, SymPy vectors, sphere shading, arc-line smoothness, and projection onto 2D segments.
What it assumes
Teaches the operation from coordinate multiplication while assuming familiarity with vectors, scalar multiplication, and basic trigonometric projection.
What you can do after
Apply it via SymPy or a 2D helper to compute alignment, lighting coefficients, orthogonality constraints, and segment projections.
How it connects
Connects to vector addition, scalar multiplication, projections, angles, orthogonality, surface normals, cross products, and signed distance functions.

Also explained in

Compare how 12 books explain inner product →

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.