Dot product
a·b = |a||b|cos(theta). Measures how aligned two vectors are, not distance, not area.
Math
Geometric meaning: is times the signed length of ‘s projection onto ‘s direction (or symmetrically the other way). If is a unit vector, IS that signed projection length directly.
What the result means:
- Sign only, direction-agnostic magnitude aside: , perpendicular,
- Full angle if you need it (expensive, avoid unless necessary):
- If both vectors are unit length, the dot product is bounded to and directly equals
Code
float dot = glm::dot(a, b);
float projLength = glm::dot(a, glm::normalize(b)); // scalar projection of a onto b
Uses in graphics
- Back-face culling — sign of N·V
- Diffuse (Lambertian) lighting: intensity ∝ max(0, N·L)
- Specular highlights (Blinn-Phong): N·H term
- Which side of a plane a point is on: sign of
planeNormal · (point - planePoint) - Camera frustum / visibility checks:
dot(cameraForward, dirToObject)to reject anything behind the camera - Closest point on a line/ray to another point (scalar projection)
Gotchas
- Dot product alone can’t tell you the exact angle, only which side of 90° you’re on — use the sign, don’t reach for
acosunless you actually need the number. - Only equals
cos(theta)directly when both vectors are normalized; otherwise it’s scaled by both magnitudes, don’t forget to divide if you need the pure angle relationship.