Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Calculation/Math2D.cs
===================================================================
diff -u -rf69d756f50ae1464a1a11f0780b6d6aa646f3114 -r72802865521b0ddd696ff95ab01573feb4bd0cb0
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Calculation/Math2D.cs (.../Math2D.cs) (revision f69d756f50ae1464a1a11f0780b6d6aa646f3114)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Calculation/Math2D.cs (.../Math2D.cs) (revision 72802865521b0ddd696ff95ab01573feb4bd0cb0)
@@ -1,4 +1,7 @@
using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.IO.Properties;
@@ -59,5 +62,68 @@
Y = (aLine*cOtherLine - aOtherLine*cLine)/determinant
};
}
+
+ ///
+ /// Determines the intersection points of a of with a vertical line
+ /// which is plotted at x=.
+ ///
+ /// A collection of segments that possibly intersect with the
+ /// vertical line at x=.
+ /// The x coordinate of the vertical line.
+ /// A of with all intersection points of the
+ /// with the vertical line at x=.
+ /// Segments which have length=0 or which are vertical, will not return an intersection point.
+ public static IEnumerable SegmentsIntersectionWithVerticalLine(IEnumerable segments, double verticalLineX)
+ {
+ var intersectionPointY = new Collection();
+
+ foreach (Segment2D segment in segments.Where(s => s.ContainsX(verticalLineX)))
+ {
+ Point2D intersectionPoint = LineIntersectionWithVerticalLine(segment.FirstPoint, segment.SecondPoint, verticalLineX);
+
+ if (intersectionPoint != null)
+ {
+ intersectionPointY.Add(intersectionPoint);
+ }
+ }
+
+ return intersectionPointY;
+ }
+
+ ///
+ /// Determines the intersection point of a line through the points and
+ /// with a vertical line at x=. If
+ /// equals , then no intersection point
+ /// will be returned.
+ ///
+ /// A which the line passes through.
+ /// Another which the line passes through.
+ /// The x coordinate of the vertical line.
+ /// The intersection point between the line through and
+ /// and the vertical line at x=; or null if
+ /// the line through and is vertical or
+ /// the points are equal.
+ private static Point2D LineIntersectionWithVerticalLine(Point2D point1, Point2D point2, double x)
+ {
+ var verticalLineFirstPoint = new Point2D
+ {
+ X = x,
+ Y = 0
+ };
+ var verticalLineSecondPoint = new Point2D
+ {
+ X = x,
+ Y = 1
+ };
+
+ try
+ {
+ return LineIntersectionWithLine(point1, point2, verticalLineFirstPoint, verticalLineSecondPoint);
+ }
+ catch (ArgumentException)
+ {
+ return null;
+ }
+ }
}
}
\ No newline at end of file