Exemplo n.º 1
0
        bool IsSegmentsReallyNear(LineSegment2d source, LineSegment2d target)
        {
            // Duplicate should return.
            if (source.StartPoint == target.StartPoint && source.EndPoint == target.EndPoint ||
                source.EndPoint == target.StartPoint && source.StartPoint == target.EndPoint)
            {
                return(false);
            }

            if (IsColinear(source, target))
            {
                return(false);
            }

            // source segment and target segment's angle should less than 20
            var sourceVector = source.Direction;
            var targetVector = target.Direction;
            var angle        = sourceVector.GetAngleTo(targetVector);

            if (angle.Larger(Math.PI / 36.0) && angle.Smaller(Math.PI * 35.0 / 36.0))
            {
                return(false);
            }

            // Check two segments' distance
            var sourceLine2d = new Line2d(source.StartPoint, source.EndPoint);
            var targetLine2d = new Line2d(target.StartPoint, target.EndPoint);
            var dist1        = sourceLine2d.GetDistanceTo(target.StartPoint);
            var dist2        = sourceLine2d.GetDistanceTo(target.EndPoint);

            // If they are both equal to 0.0, means duplicate, just return.
            if (dist1.EqualsWithTolerance(0.0, Tolerance.Global.EqualPoint) && dist2.EqualsWithTolerance(0.0, Tolerance.Global.EqualPoint))
            {
                return(false);
            }

            var dist3 = targetLine2d.GetDistanceTo(source.StartPoint);
            var dist4 = targetLine2d.GetDistanceTo(source.EndPoint);

            if ((dist1.Larger(_tolerance) || dist2.Larger(_tolerance)) &&
                (dist3.Larger(_tolerance) || dist4.Larger(_tolerance)))
            {
                return(false);
            }


            // Filter out the situation if a short segment (length < _tolerance) is connect to another.
            var pt1OnSource = source.GetClosestPointTo(target.StartPoint);
            var pt2OnSource = source.GetClosestPointTo(target.EndPoint);

            if (pt1OnSource.Point == pt2OnSource.Point)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Проверка только на наложение двух линий
        /// С учетом допусков автокада
        /// </summary>
        /// <returns></returns>
        public static bool LinesAreOverlapping(Point2d p1, Point2d p2, Point2d p3, Point2d p4)
        {
            Vector2d vector1 = p2 - p1;
            Vector2d vector2 = p4 - p3;

            if (vector1.IsParallelTo(vector2))
            {
                LineSegment2d line1 = new LineSegment2d(p1, p2);
                LineSegment2d line2 = new LineSegment2d(p3, p4);

                //Finds the two closest points between this curve and the input curve
                PointOnCurve2d[] closestPts = line2.GetClosestPointTo(line1);
                if (closestPts[0].Point.IsEqualTo(closestPts[1].Point))
                {
                    return(true);
                }
            }

            return(false);
        }