**glossary**

# Cross Product: Step-by-Step Calculations and Python Examples

*LearnDataSci is reader-supported. When you purchase through links on our site, earned commissions help support our team of writers, researchers, and designers at no extra cost to you.*

## What is a cross product?

In three-dimensional space, the cross product between two vectors, $\vec{a}$ and $\vec{b}$, produces a third vector, $\vec{c}$, perpendicular to both $\vec{a}$ and $\vec{b}$. Geometrically, the magnitude of $\vec{c}$ is equal to the area of a parallelogram whose sides are $\vec{a}$ and $\vec{b}$(see visualization below).

### Cross Product vs. Dot Product

The result of a cross product is a **vector**, whereas the result of the dot product is a scalar (a number).

## Mathematical definition

The cross product operation is denoted by the '$\times$' symbol. Below, we'll describe both the coordinate definition and geometric definition of the cross product.

### Coordinate definition

The cross product of the vectors $ \vec{a} = a_x + a_y + a_z$ and $ \vec{b} = b_x + b_y + b_z$ is derived from the determinant of the 3x3 matrix:

$$ \begin{align} \vec{a} \times \vec{b} &= \begin{vmatrix} i&j&k \\ a_x&a_y&a_z \\ b_x&b_y&b_z \end{vmatrix} \\[1em] &= \begin{vmatrix}a_y&a_z \\ b_y&b_z\end{vmatrix} i - \begin{vmatrix}a_x&a_z \\ b_x&b_z\end{vmatrix} j + \begin{vmatrix}a_x&a_y \\ b_x&b_y\end{vmatrix} k \\[1em] &= (a_yb_z-a_zb_y)\vec{i} + (a_zb_x-a_xb_z)\vec{j} + (a_xb_y-a_yb_x)\vec{k} \\[1em] \end{align} $$

Where $\vec{i} = (1, 0, 0)$, $\vec{j} = (0, 1, 0)$, and $\vec{k} = (0, 0, 1)$ are the standard unit vectors that point parallel to the x-axis, y-axis, and z-axis respectively.

Thus, the general formula for the cross product between two vectors is:

$$ \vec{a} \times \vec{b} = (a_yb_z-a_zb_y)\vec{i} + (a_zb_x-a_xb_z)\vec{j} + (a_xb_y-a_yb_x)\vec{k} $$

#### Example by hand

Given the two vectors $\vec{a} = (1, 2, 3)$ and $\vec{b} = (4, 5, 6)$, the cross product is as follows:

\begin{align} \vec{a} \times \vec{b} &= \begin{vmatrix} i&j&k \\ 1&2&3 \\ 4&5&6 \end{vmatrix} \\[1em] &= (2\times6-3\times5)\vec{i} + (3\times4-1\times6)\vec{j} + (1\times5-2\times4)\vec{k} \\[1em] &= -3\vec{i} + 6\vec{j} -3\vec{k} \end{align}

So, the cross product of $\vec{a}$ and $\vec{b}$ is a new vector with coordinates $(-3, 6, -3)$

### Geometric definition

Given two vectors $\vec{a}$ and $\vec{b}$, the cross product is defined as:

$$ \vec{a} \times \vec{b} = \|\vec{a}\|\|\vec{b}\| \sin \theta \hat{n} $$

Where:

- $\|\vec{a}\|$ and $\|\vec{b}\|$ represent the magnitudes (L2 norm) of the vectors, meaning the root of the squared elements. For example, $\|\vec{a}\| = \sqrt{a_1^2 + a_2^2 + a_3^2}$
- $\theta$ (theta) is the angle between the vectors.
- $\hat{n}$ (n hat) is the unit vector perpendicular to the given vectors.

#### Visualization

The following is an interactive geometric visualization of the cross product. Drag the vector points around to see how the cross product is affected.

### The right-hand rule

The right-hand rule is used to find the direction of the cross product's resulting vector. If you point your index finger towards the vector $\vec{a}$ and your middle finger towards the vector $\vec{b}$, your thumb will point you in the direction of $\vec{a} \times \vec{b}$.

### When is the cross product zero?

The cross product of two vectors is zero when:

- They have the same direction
- They have the exact opposite direction
- Either vector has zero length

### Algebraic properties

Cross products are **not commutative**: $\vec{a} \times \vec{b} \neq \vec{b} \times \vec{a}$, but $ \vec{a} \times \vec{b} = - (\vec{b} \times \vec{a}) $.

The cross product **is distributive over addition**: $ \vec{a} \times (\vec{b} + \vec{c}) = \vec{a} \times \vec{b} + \vec{a} \times \vec{c}$

## Python Example

First, we will create our own function for calculating a cross product, then we'll use the `cross`

function from Numpy as an alternative.

Let's create two vectors as simple Python lists:

And now using the determinant formula, we can make a function that calculates the cross product:

Passing both vectors in, we can see we've calculated the cross product calculated successfully:

Instead of writing your own function, you can simply use the `cross`

function from Numpy.

Make two numpy vectors using `np.array`

and then call `np.cross`

:

### Showing algebraic properties

We can easily use Numpy to show the algebraic properties listed above.

Showing cross products are **not commutative**:

Showing cross products are **distributive over addition**: