public static bool HasLineOfSight(this IRectangularF from, IRectangularF to, List <IRectangularF> obstacles) { var a = from.CalculateAngleTo(to); var d = Geometry.CalculateNormalizedDistanceTo(from, to); foreach (var o in obstacles) { if (o == from || o == to) { continue; } var dO = Geometry.CalculateNormalizedDistanceTo(from, o); if (dO > d) { continue; } // todo - define this curve smoothly with real math var angleDiffThreshold = d < 2 ? 180 : d < 5 ? 60 : d < 10 ? 40 : d < 20 ? 25 : d < 40 ? 20 : 15; var aO = from.CalculateAngleTo(o); var aODiff = a.DiffAngle(aO); if (aODiff < angleDiffThreshold) { return(false); } } return(true); }
public static Direction GetHitDirection(this IRectangularF rectangle, IRectangularF other) => GetDirection(rectangle.CalculateAngleTo(other));
public static float CalculateNormalizedDistanceTo(IRectangularF a, IRectangularF b) => NormalizeQuantity(a.CalculateDistanceTo(b), a.CalculateAngleTo(b), true);