Beispiel #1
0
        /// <summary>
        /// Find nearest intersect from segment of default Point.
        /// </summary>
        /// <param name="leadSegment">This segment do you want to cross</param>
        /// <param name="possibleSegments">Those segments can cross leadSegment</param>
        /// <returns>Nearest intersect or default(Point)</returns>
        public static Point GetNearestIntersect(Segment leadSegment, Segment[] possibleSegments)
        {
            double minDistance      = double.MaxValue;
            Point  nearestIntersect = default(Point);

            foreach (var segment in possibleSegments)
            {
                if (EuclideanSpaceUtils.FindIntersection(leadSegment, segment, out double x, out double y))
                {
                    Point  intersect = new Point(x, y);
                    double distance  = EuclideanSpaceUtils.Distance(leadSegment.From, intersect);
                    if (distance < minDistance)
                    {
                        minDistance      = distance;
                        nearestIntersect = intersect;
                    }
                }
            }
            return(nearestIntersect);
        }
Beispiel #2
0
 /// <summary>
 /// Calculate distance between two object.
 /// </summary>
 /// <param name="x1">X-coordinate of first object.</param>
 /// <param name="y1">Y-coordinate of first object.</param>
 /// <param name="x2">X-coordinate of second object.</param>
 /// <param name="y2">Y-coordinate of second object.</param>
 /// <returns>Distance between object</returns>
 public static double Distance(double x1, double y1, double x2, double y2)
 {
     return(EuclideanSpaceUtils.Distance(x1, y1, x2, y2));
 }
Beispiel #3
0
 /// <summary>
 /// Calculate distance between two points.
 /// </summary>
 /// <param name="point1">First point.</param>
 /// <param name="point2">Second point.</param>
 /// <returns>Distance between object</returns>
 public static double Distance(Point point1, Point point2)
 {
     return(EuclideanSpaceUtils.Distance(point1, point2));
 }