Lesson 2 of 18

3D Cross Product

The Cross Product

The cross product of a=(ax,ay,az)\mathbf{a} = (a_x, a_y, a_z) and b=(bx,by,bz)\mathbf{b} = (b_x, b_y, b_z) produces a new vector perpendicular to both:

a×b=(aybzazby,  azbxaxbz,  axbyaybx)\mathbf{a} \times \mathbf{b} = (a_y b_z - a_z b_y,\; a_z b_x - a_x b_z,\; a_x b_y - a_y b_x)

Key Properties

  • Direction: perpendicular to both a\mathbf{a} and b\mathbf{b} (right-hand rule)
  • Magnitude: a×b=absin(θ)|\mathbf{a} \times \mathbf{b}| = |\mathbf{a}| \cdot |\mathbf{b}| \cdot \sin(\theta)
  • Anti-commutative: a×b=(b×a)\mathbf{a} \times \mathbf{b} = -(\mathbf{b} \times \mathbf{a})
  • If a\mathbf{a} and b\mathbf{b} are parallel: a×b=0\mathbf{a} \times \mathbf{b} = \mathbf{0}

Geometric Meaning

The magnitude a×b|\mathbf{a} \times \mathbf{b}| equals the area of the parallelogram spanned by a\mathbf{a} and b\mathbf{b}.

Memory Aid: The Determinant Formula

a×b=ijkaxayazbxbybz\mathbf{a} \times \mathbf{b} = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k} \\ a_x & a_y & a_z \\ b_x & b_y & b_z \end{vmatrix}

Expanding along the first row gives the formula above.

Applications

  • Normal vectors to planes and surfaces
  • Torque: τ=r×F\boldsymbol{\tau} = \mathbf{r} \times \mathbf{F}
  • Area of triangles and parallelograms in 3D

Your Task

Implement void cross3(double ax, double ay, double az, double bx, double by, double bz, double *rx, double *ry, double *rz) that writes the cross product into the output pointers.

TCC compiler loading...
Loading...
Click "Run" to execute your code.