Dot Product

Method: point.dot(that)

Returns: number


Description

The dot product is a scalar value that measures how much two vectors point in the same direction. Given two vectors \(\mathbf{a}\) and \(\mathbf{b}\) originating from the same point, it is defined as:

\[\mathbf{a} \cdot \mathbf{b} = a_x b_x + a_y b_y\]

This is equivalent to:

\[\mathbf{a} \cdot \mathbf{b} = |\mathbf{a}|\,|\mathbf{b}|\cos\theta\]

where \(\theta\) is the angle between the two vectors and \(|\mathbf{v}|\) denotes the magnitude (length) of vector \(\mathbf{v}\).

Interpreting the sign

Scalar projection

Dividing the dot product by the magnitude of \(\mathbf{b}\) gives the scalar projection of \(\mathbf{a}\) onto \(\mathbf{b}\) — the signed length of \(\mathbf{a}\)’s shadow along the direction of \(\mathbf{b}\):

\[\text{proj} = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{b}|}\]

Implementation

dot(that) {
  return this.x * that.x + this.y * that.y;
}

Usage in Design

The dot product is used internally by perpendicular() to compute the parameter \(t\) that locates the foot of the perpendicular from a point onto a line. It is also used wherever two direction vectors need to be compared — for example when determining whether a snap point lies within an expected angular range.

See Also

Cross Product | Perpendicular | Development