Linear Algebra
Cross Product: Building a Perpendicular from Two Vectors
The surface normal in 3D graphics, the torque on a motor, the orientation of a drone in flight - all computed via the cross product. Unity and Unreal Engine call it every frame to compute lighting for every triangle in the scene.
- 3D graphics: triangle normal for lighting = cross product of two edge vectors
- Robotics: torque τ = r × F controls joint angles in a robot arm
- Aviation: angular momentum and gyroscopic effects use the cross product
- Computer vision: orientation of a plane in 3D reconstruction from stereo cameras
- Physics: Lorentz force on a charge in a magnetic field - F = qv × B
Cross Product: Building a Perpendicular from Two Vectors
**Every surface in a 3D game knows which way it faces.** Without that knowledge, lighting is impossible: is light hitting the front or the back? At what angle? The GPU performs this calculation for billions of pixels per second, and at its core sits the **cross product**. The operation takes two vectors lying in a plane and produces a third vector perpendicular to both. The dot product gave a number - it measured an angle. The cross product gives a vector - it builds a direction.
The **cross product** is the answer to one question that keeps showing up: *give me a vector perpendicular to these two*. Unity asks it every frame for 3D lighting. A drone's IMU asks it 400× per second to track attitude. SLAM asks it for every camera pose estimate. One formula, three billion-dollar applications - and read as a rotation-generator (not just "right-hand rule"), they stop looking like three problems and start looking like one.
What is the key idea of the concept 'Cross Product: Building a Perpendicular from Two Vectors'?
Check that the concept material has been understood.
Intuition: perpendicular to a plane
Intuition: perpendicular to a plane
Two vectors a and b define a plane. The vector c = a x b is perpendicular to that plane: c is perpendicular to a and to b simultaneously. The length of c equals the area of the parallelogram spanned by a and b. The direction follows the right-hand rule.
**Verification**: (3,0,0) x (0,2,0) = (0*0-0*2, 0*0-3*0, 3*2-0*0) = (0, 0, 6). Dot product with a: (0,0,6)·(3,0,0) = 0. Dot product with b: (0,0,6)·(0,2,0) = 0. Perpendicularity confirmed by numbers.
What is the key idea of the concept 'Intuition: perpendicular to a plane'?
Check that the concept material has been understood.
Formula
Formula
a = (a1, a2, a3), b = (b1, b2, b3) a x b = ( a2*b3 - a3*b2, <- X-component a3*b1 - a1*b3, <- Y-component a1*b2 - a2*b1 <- Z-component ) MNEMONIC (3x3 determinant): | i j k | a x b = | a1 a2 a3 | | b1 b2 b3 | PROPERTIES: |a x b| = |a| * |b| * sin(theta) <- parallelogram area a x b = -(b x a) <- anti-commutativity a x a = 0 <- zero vector (sin(0) = 0) 3D ONLY: in 2D there is no third dimension for the result.
**Anti-commutativity is a common trap**: a x b = -(b x a). With the dot product, order does not matter. With the cross product, swapping the order flips the sign of the result. If a normal points the wrong way in a 3D engine, it is almost always a wrong operand order.
What is the key idea of the concept 'Formula'?
Check that the concept material has been understood.
Right-hand rule: direction of the result
Right-hand rule: direction of the result
The direction of a x b follows the **right-hand rule**: point the index finger along a, the middle finger along b, and the thumb points in the direction of a x b.
Standard unit vectors: i=(1,0,0), j=(0,1,0), k=(0,0,1) i x j = k (X x Y = Z) <- right-hand rule j x k = i (Y x Z = X) k x i = j (Z x X = Y) and in reverse: j x i = -k (order changed - sign flipped) k x j = -i i x k = -j To remember: i -> j -> k -> i -> ... cyclic = positive. Against the cycle = negative.
What is the key idea of the concept 'Right-hand rule: direction of the result'?
Check that the concept material has been understood.
Application #1: lighting in 3D graphics (GPU)
Application #1: lighting in 3D graphics (GPU)
**Every triangle in a 3D scene rendered by Unreal Engine, Unity, or WebGL has a normal.** A normal is a vector perpendicular to the surface. The GPU uses it to compute how much light reaches the surface: the angle between the normal and the light direction gives brightness via the dot product. The normal is built from the cross product of the triangle's edges.
**Scale**: a single frame in a game like Cyberpunk 2077 contains hundreds of thousands of triangles. The GPU computes the normal and lighting for each one in parallel within milliseconds. One frame = hundreds of millions of cross product operations. That is why graphics cards are specialized vector processors.
What is the key idea of the concept 'Application #1: lighting in 3D graphics (GPU)'?
Check that the concept material has been understood.
Application #2: torque and angular velocity
Application #2: torque and angular velocity
In physics and robotics, **torque** is tau = r x F, where r is the position vector and F is the force. The result is perpendicular to both - it is the axis of rotation. Boston Dynamics robots, DJI drones, and KUKA manipulators apply this formula at every control step.
EXAMPLE: a wrench. Wrench length r = (0.2, 0.0, 0.0) meters Applied force F = (0.0, 50.0, 0.0) Newtons tau = r x F = (0.2, 0, 0) x (0, 50, 0) = (0*0 - 0*50, 0*0 - 0.2*0, 0.2*50 - 0*0) = (0, 0, 10) N*m Torque = 10 Nm along the Z axis - the bolt's rotation axis. |tau| = |r| * |F| * sin(90) = 0.2 * 50 * 1 = 10 Nm Physical meaning: the longer the wrench (|r|), the greater the torque for the same applied force.
What is the key idea of the concept 'Application #2: torque and angular velocity'?
Check that the concept material has been understood.
Application #3: camera orientation in SLAM
Application #3: camera orientation in SLAM
**SLAM** (Simultaneous Localization and Mapping) is the algorithm that robots and self-driving cars use to build a map and locate themselves within it. A camera is described by three vectors: forward (where it looks), up (scene up direction), and right. The right vector = forward x up. This is cross product in a real production system.
**Gram-Schmidt via cross product**: the pattern forward -> right (cross) -> up (cross) is part of Gram-Schmidt orthogonalization. In NeRF, 3D Gaussian Splatting, and any system requiring a camera coordinate frame - exactly this code.
What is the key idea of the concept 'Application #3: camera orientation in SLAM'?
Check that the concept material has been understood.
Triangle area via cross product
Triangle area via cross product
The length of a x b is the area of the parallelogram. A triangle's area is exactly half that. This is used in 3D rasterization to check whether a pixel falls inside a triangle (barycentric coordinates).
PARALLELOGRAM: S = |a x b| = |a| * |b| * sin(theta) TRIANGLE: S_triangle = |a x b| / 2 EXAMPLE: a = (3, 0, 0), b = (1, 2, 0) a x b = (0*0 - 0*2, 0*1 - 3*0, 3*2 - 0*1) = (0, 0, 6) |a x b| = 6 S_parallelogram = 6 S_triangle = 3 VERIFICATION via basic formula: base = |a| = 3 height = |b| * sin(theta) = sqrt(5) * sin(arctan(2)) = 2 S = 3 * 2 / 2 = 3 << matches.
What is the key idea of the concept 'Triangle area via cross product'?
Check that the concept material has been understood.
Dot product vs cross product
Dot product vs cross product
| Property | Dot product | Cross product |
|---|---|---|
| Result | Number | Vector |
| Dimension | Any | 3D only |
| Commutativity | a·b = b·a | a x b = -(b x a) |
| Geometric meaning | Cosine of angle, projection | Perpendicular, area, orientation |
| ML application | Cosine similarity, attention | Surface normals, torque, SLAM |
Cross product in industry
Three classes of tasks - one operation
| Component | Role | Details |
|---|---|---|
| GPU rendering (Unreal, Unity, WebGL) | Triangle normal for lighting | Billions of operations per second; without normals there are no shadows, highlights, or Phong/PBR shading |
| Robotics (Boston Dynamics, KUKA) | Torque and angular velocity | tau = r x F; manipulator control, balancing, inverse kinematics |
| SLAM / NeRF / 3DGS | Camera coordinate frame | right = forward x up; view matrix for any 3D algorithm |
| Physics engines (Bullet, PhysX) | Angular momentum, collisions | L = r x p; rigid body collision resolution in simulation |
What is the key idea of the concept 'Dot product vs cross product'?
Check that the concept material has been understood.
Practice: 3D lighting
Practice: 3D lighting
Interview questions
Why is a x a = 0 (the zero vector)?
- The angle between a and a is 0 degrees - |a x a| = |a| * |a| * sin(0) = 0 - Zero length means the zero vector - Geometrically: two coincident vectors span a plane with zero area - the perpendicular to it is undefined
A triangle's normal points the wrong way - how to fix it without recomputing?
- a x b = -(b x a) - just swap the operands - Alternatively, multiply the result by -1 - In 3D engines this is winding order: the order of triangle vertices determines the normal direction - Clockwise vs counter-clockwise - a setting in the graphics API (glFrontFace in OpenGL)
Does a cross product exist in 7D?
- The cross product exists only in 3D and 7D - a mathematical fact - The 7D version is linked to octonions - an 8-element algebra - Only the 3D version is used in ML - In 2D there is a 'scalar cross product' = 2x2 determinant, giving a number (area), but not a vector
What is the key idea of the concept 'Practice: 3D lighting'?
Check that the concept material has been understood.
Key takeaways
- **a x b** - vector perpendicular to both; |a x b| = parallelogram area
- **3D only**: the formula requires exactly three components
- **Anti-commutativity**: a x b = -(b x a); order determines the normal direction
- **GPU rendering**: triangle normal = cross product of two edges
- **Robotics**: torque tau = r x F; the result is the rotation axis
- **SLAM / NeRF**: right = forward x up builds the camera coordinate frame
- **numpy.cross(a, b)** - the whole operation in one line
What comes next
The cross product unlocks the geometry of 3D space
- Lines and planes — A plane's normal is built via the cross product of its edges
- Determinant — The cross product formula is the expansion of a 3x3 determinant
- Rotation matrices — Three vectors (right, up, forward) assemble into a camera rotation matrix