Linear Algebra · Theory · M1
M1-T3 — Cross Product, Lines and Planes
The cross product adds the missing sign: left or right, up or down. With it you can measure how far a robot is off its path and how far a point is from a surface.
The dot product measures how much two arrows agree but cannot tell left from right. The cross product can. In the plane it is a signed number; in space it is an arrow perpendicular to both inputs. Together with the dot product it lets you describe a path as a line, a wall or the ground as a plane, and compute the two numbers every path-following controller needs: how far along the path the robot is and how far to the side.
Learning objectives
After this lesson, you should be able to:
- Compute the 2D cross product, read its sign as left or right, and read its size as the area of a parallelogram.
- Compute the 3D cross product and use it for a perpendicular direction (a normal) and for torque.
- Write a line in parametric and normal form and compute the along-track and signed cross-track position of a point.
- Write a plane with a point and a normal, find a normal from three points, and compute the signed distance of a point from the plane.
Introduction and motivation
The dot product cannot tell left from right, and a robot must know which way to steer. The cross product supplies that sign, and the same idea measures how far a robot has strayed from its path (cross-track error) and how far a LiDAR point lies from the ground plane. These two numbers drive path following and ground segmentation in real systems.
The intuition
Stand at the origin facing along arrow u. Another arrow v points either to your left, to your right, or along your line of sight. The 2D cross product is a number whose sign answers that question: positive for left (a counter-clockwise turn from u to v), negative for right, zero when v is along u. Its size is the area of the parallelogram that u and v span.
Interactive figure. Two arrows u and v from the origin span a parallelogram that is shaded green when v is to the left of u and orange when v is to the right. The readout gives the signed cross product, the area, |u||v| sin θ and which side v is on. This figure needs JavaScript to be interactive.
Lines, and how far off one you are
A path is a line: a starting point and a direction. A robot at some point P is rarely exactly on it. Two numbers describe where it is relative to the path: how far along the path it has got (a shadow, so a dot product) and how far to the side it is (a signed cross product). The sideways one is the cross-track error, and nearly every path-following controller steers to drive it to zero.
Interactive figure. A path from A to B and a robot at P. A dashed perpendicular from P meets the path at a foot point. The readout gives the distance along the path from A to the foot, the signed sideways distance e (negative means right), and checks that s squared plus e squared equals the squared distance from A to P. This figure needs JavaScript to be interactive.
In space: perpendicular arrows and planes
In 3D the cross product of two arrows is a third arrow, perpendicular to both, with the parallelogram's area as its length and the direction given by the right-hand rule. A direction perpendicular to a surface is its normal, and a plane is exactly the set of points whose offset from a given point is perpendicular to the normal. That is how a robot describes the ground, a wall or a tabletop from a handful of sensor points.
Dot product: how much two arrows agree (a number). Cross product: how much they disagree sideways, with a direction or a sign. Between them they cover along and across.
Geometric and physical interpretation
Geometric view. In the plane the cross product is the signed area of the parallelogram two arrows span, and its sign says whether the second arrow is a left or a right turn from the first. In space it is a third arrow standing perpendicular to both, which is how a surface normal is found. Physical view. It is the torque of a force about a joint: only the part of the force perpendicular to the lever arm turns it.
The mathematics
- u × v
- the cross product. In 2D a single signed number; in 3D a vector.
- θ
- the angle from u to v, counter-clockwise positive in 2D.
- û
- the unit vector along a path or an edge.
- n, n̂
- a normal vector (perpendicular to a line or plane) and its unit version.
- s, e
- along-track distance and signed cross-track error.
The cross product
2D: u × v = ux·vy − uy·vx = |u| |v| sin θ
What it means. A signed number. Positive when v is a counter-clockwise (left) turn from u, negative for a clockwise (right) turn, zero when they are parallel. Its absolute value is the area of the parallelogram on u and v.
3D: u × v = ( uy·vz − uz·vy , uz·vx − ux·vz , ux·vy − uy·vx )
What it means. A vector perpendicular to both u and v, with length |u||v| sin θ and direction from the right-hand rule. It is zero exactly when u and v are parallel, and v × u = −(u × v). The 2D formula is the third component with z = 0.
Lines
p(t) = a + t · d normal form: n · (x − a) = 0, n = (−dy, dx)
What it means. The parametric form walks from a along the direction d. The normal form says: a point x is on the line when the offset from a is perpendicular to the left-pointing normal n.
s = û · (P − A) e = û × (P − A)
What it means. s is the shadow of the robot's offset on the path direction: how far along it has got. e is the signed sideways distance: positive when the robot is left of the direction of travel, negative when it is right. The distance from P to the (infinite) line is |e|.
Planes
n · (x − p0) = 0 n = (q − p) × (r − p) δ = n̂ · (x − p0)
What it means. A plane is all points whose offset from p0 is perpendicular to the normal n. Two edges lying in the plane, q − p and r − p, have a cross product perpendicular to both, which is a normal. The dot product of a point's offset with the unit normal is its signed distance δ from the plane: positive on the side the normal points to.
Along-track s uses the dot product, cross-track e uses the cross product, and for a plane the signed distance is a dot product with the unit normal, which itself came from a cross product.
Step-by-step derivation: why the cross product measures area, sign and distance
1. Size: the cross product is |u||v| sin θ. From the dot-product lesson, cos²θ + sin²θ = 1 gives |u|²|v|² sin²θ = |u|²|v|² − (u · v)². Now expand the right side with components:
|u|²|v|² − (u·v)² = (ux² + uy²)(vx² + vy²) − (ux·vx + uy·vy)²
= ux²vy² + uy²vx² − 2 ux vx uy vy = (ux·vy − uy·vx)²What it means. The terms ux²vx² and uy²vy² cancel and what remains is a perfect square. Taking the square root, |u||v| sin θ = |ux·vy − uy·vx|: the cross product has the size of the parallelogram area (base |u| times height |v| sin θ).
2. Sign: it is positive for a left turn. Write u = |u|(cos α, sin α) and v = |v|(cos β, sin β). Then
ux·vy − uy·vx = |u||v| (cos α sin β − sin α cos β) = |u||v| sin(β − α)
What it means. β − α is the counter-clockwise angle from u to v. Its sine is positive for angles between 0° and 180° (v to the left of u), negative between 180° and 360° (v to the right) and zero when parallel.
3. Along and across: split an offset into two perpendicular parts. Let q = P − A, let û be the unit path direction and n̂ = (−ûy, ûx) the unit normal to its left. Because û and n̂ are perpendicular unit vectors, q splits as q = s û + e n̂ with s = q · û (projection from the last lesson) and e = q · n̂ = −ûy qx + ûx qy = û × q. Then, taking lengths,
|q|² = s² + e²
What it means. The offset is the hypotenuse of a right triangle whose legs run along and across the path. This identity is a good unit test for any cross-track code.
4. A normal from three points. The edges a = q − p and b = r − p lie in the plane, so a normal must be perpendicular to both. Check that n = a × b is: the dot product a · (a × b) expands to ax(ay bz − az by) + ay(az bx − ax bz) + az(ax by − ay bx), and every term appears once with a plus and once with a minus, so the sum is 0. The same holds for b · (a × b).
5. Distance from a plane. The shortest way from a point x to the plane runs along the normal. The shadow of the offset x − p0 on n̂ is its component perpendicular to the plane, so δ = n̂ · (x − p0), from the projection derivation of the last lesson.
A worked example: how far off the path, and how tilted is the ground?
Path following. A path runs from A = (0, 0) to B = (8, 6). A robot is at P = (5, 2).
- Direction.
B − A = (8, 6), length 10, soû = (0.8, 0.6). Offsetq = P − A = (5, 2). - Along the path.
s = û · q = 0.8·5 + 0.6·2 = 4 + 1.2 = 5.2m. - Across the path.
e = û × q = 0.8·2 − 0.6·5 = 1.6 − 3.0 = −1.4m. Negative: the robot is 1.4 m to the right of the direction of travel. - Check.
s² + e² = 27.04 + 1.96 = 29and|q|² = 25 + 4 = 29. They agree.
A steering controller would therefore turn the robot slightly left (to reduce a rightward error) and keep driving forward, 5.2 m into a 10 m path.
Areas and signs. For u = (3, 0) and v = (1, 2): u × v = 3·2 − 0·1 = 6, so the parallelogram has area 6 (base 3, height 2), and v is to the left of u. Swapping gives −6. For torque, a 10 N force F = (0, 10) at the offset r = (0.5, 0) from a joint gives τ = r × F = 0.5·10 − 0·0 = 5 N·m, a counter-clockwise torque.
Ground tilt. Three LiDAR points on the ground are p = (0, 0, 0), q = (1, 0, 0.1) and r = (0, 1, 0.2) (x, y, z in metres, z up).
q − p = (1, 0, 0.1)andr − p = (0, 1, 0.2).n = (q − p) × (r − p) = (0·0.2 − 0.1·1, 0.1·0 − 1·0.2, 1·1 − 0·0) = (−0.1, −0.2, 1).|n| = √(0.01 + 0.04 + 1) = 1.0247, son̂ = (−0.0976, −0.1952, 0.9759). The ground is tilted byarccos(0.9759) = 12.6°from horizontal.- A point
x = (2, 1, 1)hasn · (x − p) = −0.2 − 0.2 + 1 = 0.6, soδ = 0.6 / 1.0247 = 0.586m above the ground plane.
Robotics application
Path following. Pure pursuit and Stanley-style controllers use the cross-track error e and the heading error as their two inputs. Both are computed with exactly the formulas above. The Navigation track's lessons on pure pursuit and Stanley and cross-track control take them from here.
Which way to turn. The sign of h × d (heading cross displacement) tells a robot whether the target is to its left or right, so the sign of its steering command. The dot product gives the magnitude of the forward part, the cross product the sideways part, and atan2(h × d, h · d) is the signed turn angle.
Torque and force at a joint. The torque of a force F applied at offset r from a joint is τ = r × F: the lever arm and the force both matter, and only the part of F perpendicular to r turns the joint. This returns in Module 8 when you relate joint torques to forces at a robot hand.
Surfaces from sensors. A depth camera or LiDAR returns points. The ground is a plane, a wall is another. A plane is recovered from points with a normal and a point, and a point is ground when |δ| is below a few centimetres. The tilt of the normal from vertical is the slope a wheeled robot faces. Module 5 fits the best plane to a whole noisy scan; here you only need the geometry of one plane.
Engineering implications and limitations
Practical rules
- Fix the orientation convention. This course uses y up and angles counter-clockwise, so a positive 2D cross product means left. Image coordinates have y down, which silently flips left and right. Decide which frame your cross products live in and stick to it.
- A path segment is not an infinite line. Before the start or after the end, the nearest point on the segment is an end point, not the foot of the perpendicular. Clamp
sto [0, length] and measure to the end point when it falls outside. - Degenerate input. A zero-length path or two identical points has no direction, so
ûdoes not exist. Handle it explicitly (distance to the point, for example). - Nearly collinear points make a poor plane. If the three points lie almost on a line, their cross product is tiny and its direction is decided by noise. Check
|n| / (|q − p| |r − p|)(which equals the sine of the angle between the edges) before trusting the normal. - A normal has no fixed sign or length.
nand−ndescribe the same plane. Pick a convention (for example, make the z component positive) and normalise before computing a signed distance. - Subtract a local origin first. With coordinates in the millions (GNSS in a global frame), differences of large numbers lose precision. Subtract a reference point before any cross product.
Limits
The cross product as a vector exists only in three dimensions (and, in a different form, seven). In 2D you use its single number; in higher dimensions the same ideas are expressed with determinants and matrices, which Modules 2 and 3 build.
Common misconceptions
“The 2D cross product is a vector.”
In the plane it is a single signed number: the z component of the 3D cross product of two vectors with z = 0. Its sign is a left/right test and its size is an area.
“A cross product of zero means a zero vector.”
It means the two arrows are parallel (or one is zero). Two non-zero arrows along the same line have u × v = 0.
“The order does not matter, as with the dot product.”
It does: v × u = −(u × v). Swapping the order flips the sign, so in 3D it flips the direction of a normal and in 2D it flips left and right.
“The distance to a path is the distance to the nearest waypoint.”
The nearest point on a path is usually between two waypoints. The cross-track error is the distance to the line, not to the closest corner.
“A plane has one normal.”
It has two unit normals, n̂ and −n̂, and infinitely many scaled copies. Any of them describes the same plane; only the sign of the signed distance changes.
Engineering takeaways
- In 2D, u × v = ux·vy − uy·vx is positive for a left turn, negative for a right turn and zero for parallel arrows; its size is the parallelogram area |u||v| sin θ.
- In 3D, u × v is perpendicular to both inputs with length |u||v| sin θ; swapping the inputs reverses it.
- A path gives two coordinates for a point P: along s = û · (P − A) and across e = û × (P − A), and s² + e² = |P − A|².
- A plane is n · (x − p0) = 0; a normal from three points is (q − p) × (r − p), and the signed distance is n̂ · (x − p0).
- Guard degenerate cases: zero-length paths, nearly collinear points, segment ends and the y-down image convention.
References and further reading
Where to read more. Free to read does not mean free to copy: follow each licence.
- Immersive Linear Algebra, chapter 4 (The Vector Product): interactive figures for the cross product and area
- 3Blue1Brown, Essence of Linear Algebra: a visual treatment of the cross product
- Modern Robotics, chapter 3 (Rigid-Body Motions): cross products and skew matrices for rotations and screws
- Navigation track: Stanley and Cross-Track Control: a controller built on the cross-track error computed here
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
For u = (2, 0) and v = (1, 3), compute u × v, say which side of u the vector v is on, and what swapping the order does. What is the area of the parallelogram?
Explanation
u × v = 2·3 − 0·1 = 6. It is positive, so v is to the left of u (a counter-clockwise turn). Swapping gives v × u = −6: the same area but the opposite sense. The parallelogram has area |6| = 6, which is base 2 times height 3.
Question 2
A robot is exactly 2 m to the left of a path that runs due north (û = (0, 1)). What is the sign of the cross-track error e = û × (P − A), and what changes if you do the arithmetic in image coordinates where y points down?
Explanation
With P − A = (−2, y) and û = (0, 1): e = 0·y − 1·(−2) = +2. Positive means left of the direction of travel, correct. In image coordinates y points down, so the picture is mirrored: the same physical situation produces the opposite sign, and “positive means left” becomes “positive means right”. Keep the geometry in one frame (y up) or flip the sign deliberately.
Question 3
Three LiDAR points p = (0, 0, 0), q = (1, 0, 0) and r = (2, 0, 0.0001) are almost on a straight line. Why is the plane normal (q − p) × (r − p) unreliable, and what quantity would you check before using it?
Explanation
The cross product is (1, 0, 0) × (2, 0, 0.0001) = (0, −0.0001, 0): its length is only 10⁻⁴ while the two edges have lengths 1 and about 2, so sin θ ≈ 5·10⁻⁵. Millimetre-scale noise on r would swing the normal to a completely different direction. Before trusting a normal, check |n| / (|q − p| |r − p|) (the sine of the angle between the edges) is not tiny, for example above 0.1, or equivalently that the triangle has real area.
What’s next
Module 1 gave you the language of vectors: positions, displacements, lengths, angles, left and right, lines and planes. Module 2 turns to matrices: operations that move, rotate and stretch all of these arrows at once.
Related content
Nothing below is required to finish this lesson.
- BeforeM1-T2: Dot Product, Norms and Angles
Compute lengths, angles and projections with the dot product, and read it as how much one direction agrees with another.
- LabM1-L1: 2D Robot Vector Navigator
Steer a simulated robot to a beacon with vectors: compute the heading, the distance and the sideways error from the planned path.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.