Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 public static Direction GetHitDirection(this IRectangularF rectangle, IRectangularF other) => GetDirection(rectangle.CalculateAngleTo(other));
Esempio n. 3
0
 public static float CalculateNormalizedDistanceTo(IRectangularF a, IRectangularF b) => NormalizeQuantity(a.CalculateDistanceTo(b), a.CalculateAngleTo(b), true);