Points and arrows (vectors)
On a grid every point has two numbers, (x, y). An arrow from point P to point Q is also two numbers: (Qx − Px, Qy − Py). It tells you how far to go right and how far to go up. Arrows are also called vectors.
Example: A = (−4, −2) and B = (3, −1). The arrow AB = (3 − (−4), −1 − (−2)) = (7, 1).
The cross product of two arrows
For two arrows u = (a, b) and v = (c, d) the cross product is one number:
u × v = a·d − b·c
Draw u and v from the same point and complete a parallelogram. Its area is |u × v|. So the cross product is a signed area. The triangle made by the same two arrows has half of that area.
Turn direction: left, right or straight
Take three points A, B, C. Compute cross = (B − A) × (C − A). This also equals (B − A) × (C − B), so it is the turn you make at B when you walk A → B → C.
- cross > 0: left turn (anticlockwise).
- cross < 0: right turn (clockwise).
- cross = 0: A, B and C lie on one straight line (collinear).
No angles, no square roots, no division. Only whole-number maths, so a computer makes no rounding error.
Area of a polygon
Pick one corner V0. Join it to the other corners. A polygon with n corners splits into n − 2 triangles (V0, Vk, Vk+1). Add the signed areas:
Area = ½ × (sum of cross(V0, Vk, Vk+1))
If the corners go anticlockwise, every term is positive. If they go clockwise, the answer is negative, so take the absolute value. The shoelace formula gives the same number: ½ |Σ (xi·yi+1 − xi+1·yi)|, going once round the corners. It works for any polygon whose sides do not cross, even one with a dent.
Convex hull
A shape is convex if a line between any two points inside it stays inside it. The convex hull of a set of points is the smallest convex shape that holds all of them. Picture nails in a board with a stretched rubber band round them.
Monotone chain method: 1) Sort the points by x (then y). 2) Build the lower chain from left to right: add each point, and while the last three points do not make a left turn, remove the middle one. 3) Do the same from right to left for the upper chain. 4) Join the two chains. The time needed is about n log n, because of the sorting.
Try it: nails and string
Draw 10 dots on paper, or push 10 pins into a cork board. Predict which dots will be on the hull. Then wrap a string or rubber band round them and check. For one corner of the band, pick the three dots A, B, C and compute the cross product: it should be positive when you walk anticlockwise.
Key formulas and definitions
- Arrow PQ = (Qx − Px, Qy − Py)
- u × v = ux·vy − uy·vx
- turn(A, B, C) = (B − A) × (C − A): > 0 left, < 0 right, = 0 straight
- Triangle area = |cross| / 2
- Polygon area = ½ |Σ (xi·yi+1 − xi+1·yi)| (shoelace)
- Convex hull: keep only left turns (remove the middle point when cross ≤ 0)
Worked examples
1. Find u × v for u = (2, 1) and v = (1, 3). What does the sign tell you?
u × v = 2×3 − 1×1 = 6 − 1 = 5. It is positive, so v is turned anticlockwise (to the left) from u. The parallelogram area is 5.
2. Walk A(0, 0) → B(4, 1) → C(6, −2). Left or right turn at B?
AB = (4, 1), BC = (2, −3). cross = 4×(−3) − 1×2 = −12 − 2 = −14. Negative, so it is a right turn.
3. Are A(1, 1), B(3, 2), C(7, 4) on one straight line?
AB = (2, 1), AC = (6, 3). cross = 2×3 − 1×6 = 0. Zero, so the three points are collinear.
4. Find the area of the triangle with A(1, 1), B(6, 2), C(3, 5).
AB = (5, 1), AC = (2, 4). cross = 5×4 − 1×2 = 18. Area = 18 / 2 = 9 square units.
5. Find the area of the polygon (0,0), (5,0), (5,3), (2,4), (0,3) using triangles from (0,0).
T1 = (0,0),(5,0),(5,3): cross (5,0)×(5,3) = 15, area 7.5. T2 = (0,0),(5,3),(2,4): cross (5,3)×(2,4) = 20 − 6 = 14, area 7. T3 = (0,0),(2,4),(0,3): cross (2,4)×(0,3) = 6, area 3. Total = 7.5 + 7 + 3 = 17.5 square units.
6. Which points are on the convex hull of (0,0), (4,0), (2,1), (4,4), (0,4), (1,2), (3,3)?
The four corners (0,0), (4,0), (4,4), (0,4) form a square. The other three points, (2,1), (1,2) and (3,3), all lie inside it. So the hull is those 4 corners, in order (0,0) → (4,0) → (4,4) → (0,4). Each turn on the way round is a left turn.
7. A, B, C are (0,0), (6,0), (3,−2). Compute the area, and say if the order A, B, C is clockwise.
AB = (6, 0), AC = (3, −2). cross = 6×(−2) − 0×3 = −12. Area = 12 / 2 = 6. A negative cross means A → B → C is clockwise.
Common mistakes
- Forgetting the minus sign: the cross product is a·d − b·c, not a·d + b·c.
- Swapping the order: u × v = −(v × u). Swapping flips left and right.
- Reporting a negative area. Take the absolute value, and use the sign only to know the direction.
- Removing a point from the hull only when cross < 0. Remove it when cross ≤ 0, so points that lie on the same line are also dropped.