Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs =================================================================== diff -u -r3854 -r3862 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 3854) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 3862) @@ -461,8 +461,8 @@ ref Point2D intersect) { Point2D ip; - var res = Routines2D.DetermineIf2DLinesIntersectStrickly(beginPoint1.X, beginPoint1.Z, endPoint1.X, endPoint1.Z, beginPoint2.X, - beginPoint2.Z, endPoint2.X, endPoint2.Z, out ip); + var res = Routines2D.DetermineIf2DLinesIntersectStrickly(beginPoint1, endPoint1, + beginPoint2, endPoint2, out ip); if (ip != null) { intersect = ip; Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs =================================================================== diff -u -r3854 -r3862 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs (.../Routines2D.cs) (revision 3854) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs (.../Routines2D.cs) (revision 3862) @@ -93,85 +93,44 @@ /// Checks if the 2D Lines strictly intersect. Strictly means that the intersection point must be part of both lines so /// extrapolated points do not count. /// - /// The point1 x. - /// The point1 z. - /// The point2 x. - /// The point2 z. - /// The point3 x. - /// The point3 z. - /// The point4 x. - /// The point4 z. + /// The point1. + /// The point2. + /// The point3. + /// The point4. /// The intersection point. /// /// Intersection status as well as the intersection point (when found, else null) /// /// - /// For connected paralllel lines, the connection point will be returned as valid intersection point. + /// For connected parallel lines, the connection point will be returned as valid intersection point. /// - public static LineIntersection DetermineIf2DLinesIntersectStrickly(double point1X, double point1Z, double point2X, double point2Z, - double point3X, double point3Z, double point4X, double point4Z, out Point2D intersectionPoint) + public static LineIntersection DetermineIf2DLinesIntersectStrickly(Point2D point1, Point2D point2, Point2D point3, + Point2D point4, out Point2D intersectionPoint) { - return DetermineIf2DLinesIntersectStrickly(point1X, point1Z, point2X, point2Z, point3X, point3Z, point4X, point4Z, + return DetermineIf2DLinesIntersectStrickly(point1, point2, point3, point4, out intersectionPoint, CEpsilon); } - + /// - /// Determines the point (aResultX, aResultY) on the line (aLine1X, aLine1Y, aLine2X, aLine2Y) with the - /// shortest possible distance to a point (aPointX, aPointY). - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void GetPointOnLineClosestTo(double aPointX, double aPointY, double aLine1X, double aLine1Y, double aLine2X, double aLine2Y, out double aResultX, out double aResultY) - { - - var lAb = Compute2DDistance(aLine1X, aLine1Y, aLine2X, aLine2Y); - var lAc = Compute2DDistance(aLine1X, aLine1Y, aPointX, aPointY); - var lBc = Compute2DDistance(aLine2X, aLine2Y, aPointX, aPointY); - - var lAClose = (Math.Pow(lAc, 2) - Math.Pow(lBc, 2) + Math.Pow(lAb, 2)) / (2 * lAb); - if (lAClose <= 0) - { - aResultX = aLine1X; - aResultY = aLine1Y; - } - else - { - if (lAClose >= lAb) - { - aResultX = aLine2X; - aResultY = aLine2Y; - } - else - { - aResultX = aLine1X + ((lAClose / lAb) * (aLine2X - aLine1X)); - aResultY = aLine1Y + ((lAClose / lAb) * (aLine2Y - aLine1Y)); - } - } - } - - /// /// Does the point exist in line. /// - /// The line point1 x. - /// The line point1 z. - /// The line point2 x. - /// The line point2 z. - /// The point x. - /// The point z. + /// The line point1. + /// The line point2. + /// The point. /// The tolerance. /// - public static bool DoesPointExistInLine(double linePoint1X, double linePoint1Z, double linePoint2X, double linePoint2Z, - double pointX, double pointZ, double tolerance) + public static bool DoesPointExistInLine(Point2D linePoint1, Point2D linePoint2, Point2D point, double tolerance) { // Function to find if lies on or close to a line (within a given tolerance) // Input - a line defined by lTwo points, a third point to test and tolerance aValue // Output - TRUE or FALSE + + double linePoint1X = linePoint1.X; + double linePoint1Z = linePoint1.Z; + double linePoint2X = linePoint2.X; + double linePoint2Z = linePoint2.Z; + double pointX = point.X; + double pointZ = point.Z; // first check whether the points are identical if (Math.Abs(linePoint1X - linePoint2X) < tolerance && Math.Abs(linePoint1Z - linePoint2Z) < tolerance) @@ -486,13 +445,16 @@ /// /// Description: Finds the Normal. FPoint1 and FPoint2 are the line coordinates /// - /// The point1 x. - /// The point1 z. - /// The point2 x. - /// The point2 z. + /// The point1. + /// The point2. /// - private static LineConstant CalculateNormalLineConstants(double point1X, double point1Z, double point2X, double point2Z) + private static LineConstant CalculateNormalLineConstants(Point2D point1, Point2D point2) { + double point1X = point1.X; + double point1Z = point1.Z; + double point2X = point2.X; + double point2Z = point2.Z; + var lLineConstant = new LineConstant { X = point2Z - point1Z, @@ -529,8 +491,8 @@ /// public static LineIntersection DetermineIf2DLinesIntersectWithExtrapolation(Point2D aPoint1, Point2D aPoint2, Point2D aPoint3, Point2D aPoint4, out Point2D aIntersectionPoint) { - var lLineConstant1 = CalculateNormalLineConstants(aPoint1.X, aPoint1.Z, aPoint2.X, aPoint2.Z); - var lLineConstant2 = CalculateNormalLineConstants(aPoint3.X, aPoint3.Z, aPoint4.X, aPoint4.Z); + var lLineConstant1 = CalculateNormalLineConstants(aPoint1, aPoint2); + var lLineConstant2 = CalculateNormalLineConstants(aPoint3, aPoint4); var lResult = DetermineIf2DLinesIntersectWithExtrapolation(lLineConstant1, lLineConstant2, out aIntersectionPoint); @@ -592,35 +554,39 @@ /// Checks if the 2D Lines strictly intersect. Strictly means that the intersection point must be part of both lines so /// extrapolated points do not count. /// - /// The point1 x. - /// The point1 z. - /// The point2 x. - /// The point2 z. - /// The point3 x. - /// The point3 zx. - /// The point4 x. - /// The point4 z. + /// The point1. + /// The point2. + /// The point3. + /// The point4. /// The intersection point. /// Non-inclusive maximum allowed distance between two possibly intersecting endpoints of the lines /// /// Intersection status as well as the intersection point (when found, else null) /// /// - /// For connected paralllel lines, the connection point will be returned as valid intersection point. + /// For connected parallel lines, the connection point will be returned as valid intersection point. /// - private static LineIntersection DetermineIf2DLinesIntersectStrickly(double point1X, double point1Z, double point2X, double point2Z, - double point3X, double point3Z, double point4X, double point4Z, out Point2D intersectionPoint, double tolerance) + private static LineIntersection DetermineIf2DLinesIntersectStrickly(Point2D point1, Point2D point2, Point2D point3, + Point2D point4, out Point2D intersectionPoint, double tolerance) { - var lineConstant1 = CalculateNormalLineConstants(point1X, point1Z, point2X, point2Z); - var lineConstant2 = CalculateNormalLineConstants(point3X, point3Z, point4X, point4Z); + var point1X = point1.X; + var point1Z = point1.Z; + var point2X = point2.X; + var point2Z = point2.Z; + var point3X = point3.X; + var point3Z = point3.Z; + var point4X = point4.X; + var point4Z = point4.Z; + var lineConstant1 = CalculateNormalLineConstants(point1, point2); + var lineConstant2 = CalculateNormalLineConstants(point3, point4); var result = DetermineIf2DLinesIntersectWithExtrapolation(lineConstant1, lineConstant2, out intersectionPoint); if (result == LineIntersection.Intersects) { //check if lies on the line and is not somewhere outside ! - if (!(DoesPointExistInLine(point1X, point1Z, point2X, point2Z, intersectionPoint.X, intersectionPoint.Z, tolerance) && - DoesPointExistInLine(point3X, point3Z, point4X, point4Z, intersectionPoint.X, intersectionPoint.Z, tolerance))) + if (!(DoesPointExistInLine(point1, point2, intersectionPoint, tolerance) && + DoesPointExistInLine(point3, point4, intersectionPoint, tolerance))) { intersectionPoint = null; result = LineIntersection.NoIntersection; Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/LineHelper.cs =================================================================== diff -u -r3522 -r3862 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/LineHelper.cs (.../LineHelper.cs) (revision 3522) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/LineHelper.cs (.../LineHelper.cs) (revision 3862) @@ -45,8 +45,8 @@ var point4 = new Point2D(line2.EndPoint.X, line2.EndPoint.Z); Point2D ip; - var res = Routines2D.DetermineIf2DLinesIntersectStrickly(point1.X, point1.Z, point2.X, point2.Z, - point3.X, point3.Z, point4.X, point4.Z, out ip); + var res = Routines2D.DetermineIf2DLinesIntersectStrickly(point1, point2, point3, + point4, out ip); if (ip != null) { intersectPoint.X = ip.X; Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryCurve.cs =================================================================== diff -u -r3522 -r3862 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryCurve.cs (.../GeometryCurve.cs) (revision 3522) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryCurve.cs (.../GeometryCurve.cs) (revision 3862) @@ -200,7 +200,7 @@ public bool ContainsPoint(Point2D point, double tolerance = GeometryConstants.Accuracy * 0.5) { return HeadPoint != null && EndPoint != null && - Routines2D.DoesPointExistInLine(HeadPoint.X, HeadPoint.Z, EndPoint.X, EndPoint.Z, point.X, point.Z, tolerance); + Routines2D.DoesPointExistInLine(HeadPoint, EndPoint, point, tolerance); } /// Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/LayerDetector.cs =================================================================== diff -u -r3854 -r3862 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/LayerDetector.cs (.../LayerDetector.cs) (revision 3854) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/LayerDetector.cs (.../LayerDetector.cs) (revision 3862) @@ -157,8 +157,8 @@ var verticalEndPoint = new Point2D(verticalXCoordinate, minvalue); Point2D intersectionPoint; - LineIntersection intersectionResult = Routines2D.DetermineIf2DLinesIntersectStrickly(verticalHeadPoint.X, verticalHeadPoint.Z, - verticalEndPoint.X, verticalEndPoint.Z, aHeadpoint.X, aHeadpoint.Z, aEndPoint.X, aEndPoint.Z, out intersectionPoint); + LineIntersection intersectionResult = Routines2D.DetermineIf2DLinesIntersectStrickly(verticalHeadPoint, + verticalEndPoint, aHeadpoint, aEndPoint, out intersectionPoint); if (intersectionResult == LineIntersection.Intersects) { @@ -167,9 +167,9 @@ else if (intersectionResult == LineIntersection.NoIntersection || intersectionResult == LineIntersection.Parallel) { const double cEpsilon = 1.0e-3; - if ((Routines2D.DoesPointExistInLine(verticalHeadPoint.X, verticalHeadPoint.Z, verticalEndPoint.X, verticalEndPoint.Z, - aHeadpoint.X, aHeadpoint.Z, cEpsilon)) && (Routines2D.DoesPointExistInLine(verticalHeadPoint.X, verticalHeadPoint.Z, - verticalEndPoint.X, verticalEndPoint.Z, aEndPoint.X, aEndPoint.Z, cEpsilon))) + if ((Routines2D.DoesPointExistInLine(verticalHeadPoint, verticalEndPoint, + aHeadpoint, cEpsilon)) && (Routines2D.DoesPointExistInLine(verticalHeadPoint, + verticalEndPoint, aEndPoint, cEpsilon))) { AddPointToList(new LayerIntersectionPoint(aHeadpoint, aSurfaceRefKey)); AddPointToList(new LayerIntersectionPoint(aEndPoint, aSurfaceRefKey));