/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static Point LineIntersection(this Line line1, Line line2, bool useInfiniteLines = false, double tolerance = Tolerance.Distance, double angleTolerance = Tolerance.Angle) { double sqTol = tolerance * tolerance; Line l1 = line1.DeepClone(); Line l2 = line2.DeepClone(); l1.Infinite |= useInfiniteLines; l2.Infinite |= useInfiniteLines; BH.oM.Reflection.Output <double, double> intParamsOutput = l1.SkewLineProximity(l2, angleTolerance); if (intParamsOutput == null) { return(null); } else { double[] intParams = new double[] { intParamsOutput.Item1, intParamsOutput.Item2 }; double t1 = intParams[0]; double t2 = intParams[1]; Point intPt1 = l1.Start + t1 * (l1.End - l1.Start); Point intPt2 = l2.Start + t2 * (l2.End - l2.Start); if (intPt1.SquareDistance(intPt2) <= sqTol) { Point intPt = (intPt1 + intPt2) * 0.5; if (!l1.Infinite && ((t1 < 0 && l1.Start.SquareDistance(intPt) > sqTol) || (t1 > 1 && l1.End.SquareDistance(intPt) > sqTol))) { return(null); } if (!l2.Infinite && ((t2 < 0 && l2.Start.SquareDistance(intPt) > sqTol) || (t2 > 1 && l2.End.SquareDistance(intPt) > sqTol))) { return(null); } return(intPt); } return(null); } }
/***************************************************/ /**** Public Methods - Curve/Curve ****/ /***************************************************/ public static double Distance(this ICurve curve1, ICurve curve2, double tolerance = Tolerance.Distance) { BH.oM.Reflection.Output <Point, Point> results = curve1.ICurveProximity(curve2, tolerance); return(results.Item1.Distance(results.Item2)); }