← Lessons

quiz vs the machine

Silver1100

Algorithms

Cross Product Orientation

One signed value decides whether three points turn left, turn right, or sit on a line.

4 min read · intro · beat Silver to climb

The orientation question

Given three points in order, do they make a left turn, a right turn, or stay collinear? This single primitive underlies hulls, intersections, and polygon tests.

Using the cross product

Form two vectors from the first point to the second and from the first point to the third. The two dimensional cross product of these vectors is a signed scalar.

  • A positive sign means a counterclockwise, or left, turn.
  • A negative sign means a clockwise, or right, turn.
  • A zero sign means the three points are collinear.

Why a sign is enough

The cross product equals the signed area of the parallelogram the two vectors span. Area on one side of the line is positive, the other side negative, and a flat triangle has zero area. So the sign alone answers the turn without computing any angle.

Robustness notes

With integer coordinates this test is exact, which is why competitive solutions prefer integers. With floating point you must compare against a small tolerance to avoid misclassifying near collinear points.

Key idea

The signed cross product of two vectors from a shared point classifies three points as a left turn, right turn, or collinear, giving an exact integer primitive for nearly every plane algorithm.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a positive two dimensional cross product indicate for three ordered points?

2. Why are integer coordinates preferred for the orientation test?

3. Geometrically, the cross product equals what quantity?