Ejemplo n.º 1
0
        public static SegmentIntersectionType ColinearSegmentIntersection(SegRat2 s, SegRat2 t, ref VecRat2 pointIntersection, ref SegRat2 segmentIntersection)
        {
            //This check is important for handling degenerate cases like s = [(x,y), (x,y)).
            if (s.IsEmpty() || t.IsEmpty())
            {
                return(SegmentIntersectionType.None);
            }

            //This check is important because the LineProjectionTransform can only be formed with a non-point segment.
            if (s.IsPoint())
            {
                if (ColinearPointInSegment(s.A, t))
                {
                    pointIntersection = s.A;
                    return(SegmentIntersectionType.Point);
                }
                else
                {
                    return(SegmentIntersectionType.None);
                }
            }

            LineProjectionTransform transform = new LineProjectionTransform(s);
            SegRat1 proj_s = transform.Project(s);
            SegRat1 proj_t = transform.Project(t);

            Rational proj_pointIntersection   = new Rational();
            SegRat1  proj_segmentIntersection = new SegRat1();

            SegmentIntersectionType result = SegmentIntersection(
                proj_s, proj_t, ref proj_pointIntersection, ref proj_segmentIntersection);

            if (result == SegmentIntersectionType.Point)
            {
                pointIntersection = transform.Unproject(proj_pointIntersection);
            }
            else if (result == SegmentIntersectionType.Segment)
            {
                segmentIntersection = transform.Unproject(proj_segmentIntersection);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static bool ColinearPointInSegment(VecRat2 p, SegRat2 s)
        {
            LineProjectionTransform transform = new LineProjectionTransform(s);

            return(PointInSegment(transform.Project(p), transform.Project(s)));
        }