To test whether two shapes are separated along a direction, you flatten each onto that direction and get an interval. Today you build that projection.
Project a polygon's vertices onto an axis and return the min and max of the shadow interval.
To decide whether two shapes are separated along some direction, you project each onto that direction: take the dot product of every vertex with the axis, which gives each vertex’s position along it, and keep the smallest and largest. That min-max pair is the shape’s shadow on the axis - a 1D interval standing in for the whole 2D shape as seen from that direction. Using a unit axis keeps those numbers as real distances.
This reduces a hard 2D question to an easy 1D one: two intervals either overlap or they
do not. The square’s shadow on the x axis runs from -1 to 1, and on the diagonal it
stretches to the corner distance, about 1.4142. The next lesson compares two such
intervals to detect a gap; project both shapes onto every candidate axis and you have
the full Separating Axis Theorem.
type Interval struct{ Min, Max float64 }func Project(verts []Vec2, axis Vec2) Interval {d := Dot(verts[0], axis)iv := Interval{d, d}for _, v := range verts[1:] {p := Dot(v, axis) // scalar position along the axis// widen iv.Min / iv.Max to include p}return iv}