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):
This is equivalent to:
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:
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.