Cross Product

Method: point.cross(that)

Returns: number


Description

In 2D, the cross product of two vectors \(\mathbf{a}\) and \(\mathbf{b}\) is a scalar (the \(z\)-component of the 3D cross product with the vectors embedded in the \(xy\)-plane):

\[\mathbf{a} \times \mathbf{b} = a_x b_y - a_y b_x\]

This is equivalent to:

\[\mathbf{a} \times \mathbf{b} = |\mathbf{a}|\,|\mathbf{b}|\sin\theta\]

where \(\theta\) is the signed angle measured counter-clockwise from \(\mathbf{a}\) to \(\mathbf{b}\).

The magnitude equals the area of the parallelogram formed by the two vectors, and equivalently twice the area of the triangle they enclose.

Interpreting the sign

Turn direction test

Given three points \(A\), \(B\), \(C\), the cross product of \(\overrightarrow{AB}\) and \(\overrightarrow{AC}\) tells you the winding order:

\[\overrightarrow{AB} \times \overrightarrow{AC} = (B_x - A_x)(C_y - A_y) - (B_y - A_y)(C_x - A_x)\]
  • Positive\(A \to B \to C\) turns left (counter-clockwise)

  • Zero — the three points are collinear

  • Negative\(A \to B \to C\) turns right (clockwise)

Implementation

cross(that) {
  return this.x * that.y - this.y * that.x;
}

Usage in Design

The cross product is used to determine arc sweep direction (clockwise vs counter-clockwise) and to test the winding order of geometry — for example, when deciding which side of a line a point lies on, or when resolving arc direction during polyline arc-segment creation.

See Also

Dot Product | Development