Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 62 ยท Getting Started

The Cross Product

Learn the 3D cross product, the right-hand rule, how its length gives parallelogram area, how to find normal vectors, and how to use np.cross safely.

The dot product turns two vectors into a number. The cross product turns two vectors in three dimensions into a third vector that is perpendicular to both. That perpendicular vector is exactly what you need to find the direction a surface faces, the axis of a rotation, or the area of a flat patch.

The cross product only exists in three dimensions (with a close cousin in two), so this lesson stays in 3D. You will learn the formula, the right-hand rule that fixes its direction, the area it measures, and some traps that catch beginners.

The formula

For a = (a1, a2, a3) and b = (b1, b2, b3):

TEXT
a x b = ( a2*b3 - a3*b2,
          a3*b1 - a1*b3,
          a1*b2 - a2*b1 )

Each component is a small two-by-two cross-multiplication of the other two coordinates, with the middle one arranged cyclically. You do not need to memorize it; NumPy has it as np.cross. A good sanity check is the three axis vectors: x_hat x y_hat = z_hat, y_hat x z_hat = x_hat, z_hat x x_hat = y_hat.

Python Cross product of the axis vectors

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For a = (1, 2, 3) and b = (4, 5, 6) the answer is (-3, 6, -3). Check the first component by hand: 2*6 - 3*5 = 12 - 15 = -3.

Direction: perpendicular and the right-hand rule

The result a x b is perpendicular to both a and b, so its dot product with each is zero. But two opposite vectors are both perpendicular to a plane, so which one do you get? The right-hand rule decides: point the fingers of your right hand along a, curl them toward b, and your thumb shows the direction of a x b.

Reading the cross product

Direction Perpendicular to both input vectors.
Right-hand rule Fingers from a to b, thumb gives the result.
Length The area of the parallelogram they span.

Swap the inputs and the arrow flips.

1 / 2

Because of the right-hand rule the cross product is anti-commutative: b x a = -(a x b). The order matters, and swapping it reverses the result.

Python Perpendicular and anti-commutative

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Both dot products come out as exactly 0, confirming that c is perpendicular to the plane of a and b. Crossing a vector with a parallel vector gives the zero vector, because two parallel arrows span no plane at all and there is no unique perpendicular direction.

Length: the area of a parallelogram

The length of the cross product is

TEXT
||a x b|| = ||a|| * ||b|| * sin(theta)

where theta is the angle between the vectors. This is exactly the area of the parallelogram whose sides are a and b (base times height). A triangle with the same two sides has half that area. Compare with the dot product, which used cos(theta): the dot product measures alignment, the cross product measures how much the vectors "fan out".

Python Area of a parallelogram and a triangle

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The rectangle area is 6, as expected. For the triangle we take two edge vectors from one corner, cross them, and halve the length.

Normal vectors

A normal vector points straight out of a surface. To find the normal of a flat triangle with corners p, q, r, cross two of its edges. Graphics programs use normals to decide how brightly a surface is lit, and physics uses them to compute forces on a wall or a plane. Dividing by the length gives a unit normal, as in Length, Distance and Unit Vectors.

Python The unit normal of a triangle

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The last two lines show how a plane is defined: all points x with n . (x - p) = 0. Any combination of the two edges stays in the plane, so the test comes out true.

Pitfalls to avoid

  • Only 3D. np.cross works on vectors with 3 components (or 2, where it returns a single number, the z-component, and newer NumPy versions deprecate that case). Do not expect a cross product in 5D.
  • Order matters. a x b and b x a point in opposite directions. A flipped normal can make a lit surface look black in graphics.
  • Not associative. (a x b) x c is generally different from a x (b x c).
  • Zero for parallel inputs. A zero result means the vectors are parallel (or one is zero). Check for this before normalizing.
  • Rows versus columns. With matrices, np.cross works along the last axis by default, so an (n, 3) array of vectors crosses row by row.
Python Cross products of many vectors at once

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The third row is parallel to its partner, so its cross product is the zero vector, a quick way to detect parallel pairs in bulk.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does the cross product of two 3D vectors return?

    Unlike the dot product, the cross product returns a vector, and that vector is perpendicular to both inputs.
  2. 2. If a x b = (0, 0, 5), what is b x a?

    The cross product is anti-commutative: swapping the inputs flips the sign of the result.
  3. 3. What does the length of a x b measure?

    ||a x b|| = ||a|| ||b|| sin(theta), the base times height of the parallelogram.
  4. 4. You get the zero vector from np.cross(a, b) with non-zero a and b. What does it mean?

    sin(theta) is zero when the angle is 0 or 180 degrees, so the vectors lie on the same line.
  5. 5. How do you get the area of a triangle with corners p, q, r?

    The cross product of two edges gives the parallelogram area; the triangle is half of it.

Summary

  • a x b combines two 3D vectors into a third vector perpendicular to both; NumPy computes it with np.cross.
  • The right-hand rule gives its direction, and b x a = -(a x b).
  • Its length is ||a|| ||b|| sin(theta), the area of the parallelogram on a and b; half of it is the triangle area.
  • Crossing two edges of a surface gives a normal vector; divide by the norm for a unit normal.
  • Parallel vectors give the zero vector, the operation is not associative, and it is defined for 3D vectors.

Next up: from single vectors to grids of numbers in Matrices.