public override Projection Project(Vector2 a) { Projection p = new Projection(); p.Axis = a; p.Min = float.MaxValue; p.Max = float.MinValue; foreach (Vector2 v in this.GetTransformedVertices()) { float d = Vector2.Dot(v, a); if (d < p.Min) p.Min = d; if (d > p.Max) p.Max = d; } return p; }
/// <summary> /// calculates the separation distance between projection intervals. will be negative if they overlap. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static float IntervalDist(Projection a, Projection b) { if (a.Axis != b.Axis) throw new Exception("oh shit, someone divided by zero.\r\n I SWEAR IT WASN'T ME."); if (a.Min < b.Min) return b.Min - a.Max; return a.Min - b.Max; }