Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Calculation/Math2D.cs =================================================================== diff -u -r2da86d14cee084c7d6bfa52136d387cdcdb0a025 -r602479eb3666493485aee246d56b08958a6fc958 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Calculation/Math2D.cs (.../Math2D.cs) (revision 2da86d14cee084c7d6bfa52136d387cdcdb0a025) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Calculation/Math2D.cs (.../Math2D.cs) (revision 602479eb3666493485aee246d56b08958a6fc958) @@ -1,6 +1,5 @@ using System; using Ringtoets.Piping.Data; -using Ringtoets.Piping.IO.Properties; namespace Ringtoets.Piping.IO.Calculation { @@ -14,27 +13,40 @@ /// public const double EpsilonForComparisons = 1e-8; + /// + /// Determines the intersection point of a line which passes through the and + /// the ; and a line which passes through the + /// and the . When the lines are parallel, then null will be returned, + /// as no intersection point exists. + /// + /// A which the first line passes through. + /// Another which the first line passes through. + /// A which the second line passes through. + /// Another which the second line passes through. + /// An with coordinates at the point where the lines intersect. Or null when no + /// intersection point exists (lines are parallel). /// /// Taken from: https://www.topcoder.com/community/data-science/data-science-tutorials/geometry-concepts-line-intersection-and-its-applications/ /// Based on https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection /// - public static Point2D LineIntersectionWithLine(Point2D firstPoint, Point2D secondPoint, Point2D verticalLineFirstPoint, Point2D verticalLineSecondPoint) + public static Point2D LineIntersectionWithLine(Point2D firstPoint, Point2D secondPoint, Point2D thirdPoint, Point2D fourthPoint) { var aLine = secondPoint.Y - firstPoint.Y; var bLine = firstPoint.X - secondPoint.X; - var cLine = aLine * firstPoint.X + bLine * firstPoint.Y; + var cLine = aLine*firstPoint.X + bLine*firstPoint.Y; - var aOtherLine = verticalLineSecondPoint.Y - verticalLineFirstPoint.Y; - var bOtherLine = verticalLineFirstPoint.X - verticalLineSecondPoint.X; - var cOtherLine = aOtherLine * verticalLineFirstPoint.X + bOtherLine * verticalLineFirstPoint.Y; + var aOtherLine = fourthPoint.Y - thirdPoint.Y; + var bOtherLine = thirdPoint.X - fourthPoint.X; + var cOtherLine = aOtherLine*thirdPoint.X + bOtherLine*thirdPoint.Y; - var determinant = aLine * bOtherLine - aOtherLine * bLine; + var determinant = aLine*bOtherLine - aOtherLine*bLine; if (Math.Abs(determinant) < EpsilonForComparisons) { return null; } - return new Point2D { + return new Point2D + { X = (bOtherLine*cLine - bLine*cOtherLine)/determinant, Y = (aLine*cOtherLine - aOtherLine*cLine)/determinant };