/// <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); }
/// <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) { return(EuclideanSpaceUtils.GetNearestIntersect(leadSegment, possibleSegments)); }
/// <summary> /// Find intersect of two segments. /// </summary> /// <param name="segment1">First segment.</param> /// <param name="segment2">Second segment.</param> /// <returns>True if this segments intersect each other.</returns> public static bool FindIntersection(Segment segment1, Segment segment2, out double x, out double y) { return(EuclideanSpaceUtils.FindIntersection(segment1, segment2, out x, out y)); }
/// <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)); }
/// <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)); }