Пример #1
0
        public override DrawingPoint GetClosestPoint(Vector pos)
        {
            updateRadius();
            if (Point1.dist(pos) < Radius / 2 && Point1.dist(pos) < Point2.dist(pos))
            {
                return(Point1);
            }
            else if (Point2.dist(pos) < Radius / 2)
            {
                return(Point2);
            }
            else
            {
                Vector v2 = (pos - Point2.Point), v1 = (pos - Point1.Point);
                v2.Normalize(); v1.Normalize();

                if (Dir * v2 >= 0)
                {
                    radiusUtilityPoint.Point = Point2.Point + v2 * Radius;
                }
                else if (-Dir * v1 >= 0)
                {
                    radiusUtilityPoint.Point = Point1.Point + v1 * Radius;
                }
                else
                {
                    Vector orth = new Vector(-Dir.Y, Dir.X) * ((pos - Point2.Point) * new Vector(-Dir.Y, Dir.X));
                    orth.Normalize();
                    radiusUtilityPoint.Point = Point1.Point + Dir * ((pos - Point1.Point) * Dir) + orth * Radius;
                }
                return(radiusUtilityPoint);
            }
        }
Пример #2
0
 protected void updateRadius()
 {
     rad = Position.dist(radiusUtilityPoint.Point);
 }