Points, Vectors, and Surface Direction
A point says where something is; a vector says how far and in which direction to move. From A=(1,2) to B=(4,6), the displacement is B-A=(3,4), with length √(3²+4²)=5.
Make the length one
Dividing a vector by its length produces a unit vector in the same direction. This is normalization. A zero-length vector needs separate handling because division is undefined.
import math
v = (3, 4)
length = math.sqrt(v[0] ** 2 + v[1] ** 2)
unit = (v[0] / length, v[1] / length)
print(unit)
The result is (0.6, 0.8). Unit vectors are useful for direction comparisons and lighting.
Dot products and normals
A dot product sums corresponding component products: (a,b)·(c,d) = ac+bd. For unit vectors it is the cosine of their angle: 1 for the same direction, 0 for perpendicular directions, and -1 for opposites.
A normal is perpendicular to a surface. Its dot product with the light direction measures how directly the light faces the surface. For a triangle, the cross product of two edges gives a normal. Reversing the edge order reverses its direction.
Check your understanding
Vectors (10,0) and (1,0) point the same way. What can go wrong if they are used unnormalized in a lighting dot product?
Show explanation
Their lengths can make the results differ tenfold despite identical directions. Normalize when the calculation needs only the angle. Distinguish position, length, and direction.