public bool MinimumTranslationVectorWithContainment(Vector2[] vertices1, Vector2[] vertices2, out MinimumTranslationVector?mtv) { double overlap = Double.PositiveInfinity; Vector2 smallest = default(Vector2); Vector2[] axes1 = GetAxes(vertices1); Vector2[] axes2 = GetAxes(vertices2); for (int i = 0; i < axes1.Length; i++) { Vector2 axis = axes1[i]; Projection p1 = Project(vertices1, axis); Projection p2 = Project(vertices2, axis); if (!p1.Overlap(p2)) { mtv = default(MinimumTranslationVector?); return(false); } else { double o = p1.GetOverlap(p2); if (p1.Contains(p2) || p2.Contains(p1)) { double mins = Math.Abs(p1.Min - p2.Min); double maxs = Math.Abs(p1.Max - p2.Max); if (mins < maxs) { o += mins; } else { o += maxs; } } if (o < overlap) { overlap = o; smallest = axis; } } } for (int i = 0; i < axes2.Length; i++) { Vector2 axis = axes2[i]; Projection p1 = Project(vertices1, axis); Projection p2 = Project(vertices2, axis); if (!p1.Overlap(p2)) { mtv = default(MinimumTranslationVector?); return(false); } else { double o = p1.GetOverlap(p2); if (p1.Contains(p2) || p2.Contains(p1)) { double mins = Math.Abs(p1.Min - p2.Min); double maxs = Math.Abs(p1.Max - p2.Max); if (mins < maxs) { o += mins; } else { o += maxs; } } if (o < overlap) { overlap = o; smallest = axis; } } } mtv = new MinimumTranslationVector(smallest, overlap); return(true); }
public double GetOverlap(Projection p) { return(!this.Overlap(p) ? 0.0 : Math.Abs(Math.Max(this.Min, p.Min) - Math.Min(this.Max, p.Max))); }
public bool Contains(Projection p) { return(this.Min <= p.Min && this.Max >= p.Max); }
public bool Overlap(Projection p) { return(!(this.Min > p.Max || p.Min > this.Max)); }