private static float?ResponseAcrossLine(ProjectionLine line1, ProjectionLine line2) { if (line1.Start <= line2.Start && line1.End >= line2.Start) // use the >= operator { return(line2.Start - line1.End); } else if (line2.Start <= line1.Start && line2.End >= line1.Start) // use the >= operator { return(line2.End - line1.Start); } return(null); }
private static ProjectionLine ProjectLine(Vector2[] points, Vector2 normal) { var projectionLine = new ProjectionLine() { Start = float.MaxValue, End = float.MinValue }; foreach (var p in points) { var projectionScale = DotProduct(p, normal); projectionLine.Start = Math.Min(projectionScale, projectionLine.Start); projectionLine.End = Math.Max(projectionScale, projectionLine.End); } return(projectionLine); }