private static bool IsBelowThreshold(Pnt3D sourcePoint, Pnt3D touchPoint, Pnt3D nonIntersectingTargetPnt, double tolerance) { // Target starts (just?) after source, target touches source interior //Pnt3D touchPoint = targetLine.GetPointAlong(_source1Factor, true); double distanceFromStartToTouchPoint = touchPoint.GetDistance(sourcePoint, true); double alpha = GeomUtils.GetAngle2DInRad(sourcePoint, touchPoint, nonIntersectingTargetPnt); if (alpha < Math.PI / 2) // smaller 90° { double threshold = tolerance / Math.Sin(alpha); if (distanceFromStartToTouchPoint < threshold) { return(true); } } return(false); }
/// <summary> /// The perpendicular distance of the infinite line defined by the Start/End points of this /// line to the specified point. /// </summary> /// <param name="point"></param> /// <param name="inXY"></param> /// <param name="distanceAlongRatio">The distance-along-ratio of the closest point on the line.</param> /// <param name="pointOnLine"></param> /// <returns></returns> public double GetDistancePerpendicular(Pnt3D point, bool inXY, out double distanceAlongRatio, out Pnt3D pointOnLine) { // http://geomalgorithms.com/a02-_lines.html#Distance-to-Infinite-Line Pnt3D w = point - StartPoint; double c1, c2; if (inXY) { c1 = GeomUtils.DotProduct(w.X, w.Y, 0, DirectionVector.X, DirectionVector.Y, 0); c2 = DirectionVector.Length2DSquared; } else { c1 = GeomUtils.DotProduct(w, DirectionVector); c2 = DirectionVector.LengthSquared; } if (c2 < double.Epsilon) { // 0-length line: Distance to StartPoint distanceAlongRatio = 0; pointOnLine = (Pnt3D)StartPoint.Clone(); return(StartPoint.GetDistance(point, inXY)); } distanceAlongRatio = c1 / c2; pointOnLine = (Pnt3D)(StartPoint + distanceAlongRatio * DirectionVector); return(pointOnLine.GetDistance(point, inXY)); }