← Lessons

quiz vs the machine

Silver1050

Algorithms

The Cross Product and Orientation Test

Decide if three points turn left, turn right, or stay straight with one signed number.

4 min read · intro · beat Silver to climb

A signed area in disguise

Most computational geometry rests on one tiny tool: the cross product of two vectors in the plane. Given three points, you form two vectors that share a common starting point and compute a single signed number from their coordinates. That number is twice the signed area of the triangle they span.

Reading the sign

The sign tells you how the points turn:

  • A positive value means the three points make a left turn, also called counterclockwise.
  • A negative value means a right turn, or clockwise.
  • A zero value means the points are collinear, lying on one straight line.

This is the orientation test, and almost every hull, intersection, and polygon routine calls it.

Why it matters

Because the test is just multiplications and a subtraction, it avoids slow division and square roots. With integer inputs it stays exact, so you sidestep floating point error that would otherwise make borderline cases unreliable. You can chain orientation tests to walk around a shape and always know which way you are bending.

Key idea

The cross product of two edge vectors gives a signed area whose sign reveals left turn, right turn, or collinear in constant time.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a zero cross product of the two edge vectors mean?

2. Why prefer the orientation test over computing angles?

3. A positive cross product value indicates which turn direction?