Exemple #1
0
        public static IEnumerable <IntersectionInfo> IntersectLineArc(Line line, Arc arc, ExtendType?coerceArcExtendType)
        {
            var points = new Point3dCollection();

            line.IntersectWith(arc, Intersect.ExtendBoth, points, IntPtr.Zero, IntPtr.Zero);
            if (points.Count <= 0)
            {
                return(new IntersectionInfo[0]);
            }

            // NOTE: Use Line's GetParameterAtPoint will throw exception if the intersect point is
            // on the line's extension, but LineSegment3d.GetParameterOf is available, so I convert
            // the Line to LineSegment3d here.
            var lineSegment = new LineSegment3d(line.StartPoint, line.EndPoint);
            var circularArc = new CircularArc3d(arc.Center, arc.Normal, arc.Normal.GetPerpendicularVector(), arc.Radius,
                                                arc.StartAngle, arc.EndAngle);

            var result = new List <IntersectionInfo>();

            foreach (Point3d point in points)
            {
                var lineParam      = lineSegment.GetParameterOf(point);
                var lineExtendType = ParamToExtendTypeForLine(lineParam);

                var arcParam      = circularArc.GetParameterOf(point);
                var arcExtendType = ParamToExtendTypeForArc(circularArc, arcParam, coerceArcExtendType);
                result.Add(new IntersectionInfo(lineExtendType, arcExtendType, point));
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Calculate intersection point of two line.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public static IntersectionInfo InsersectLines(Line source, Line target)
        {
            var points = new Point3dCollection();

            source.IntersectWith(target, Intersect.ExtendBoth, points, IntPtr.Zero, IntPtr.Zero);
            if (points.Count <= 0)
            {
                return(null);
            }

            // NOTE: Use Line's GetParameterAtPoint will throw exception if the intersect point is
            // on the line's extension, but LineSegment3d.GetParameterOf is available, so I convert
            // the Line to LineSegment3d here.
            var intersectPoint    = points[0];
            var sourceLineSegment = new LineSegment3d(source.StartPoint, source.EndPoint);
            var targetLineSegment = new LineSegment3d(target.StartPoint, target.EndPoint);

            var sourceParam      = sourceLineSegment.GetParameterOf(intersectPoint);
            var sourceExtendType = ParamToExtendTypeForLine(sourceParam);

            var targetParam      = targetLineSegment.GetParameterOf(intersectPoint);
            var targetExtendType = ParamToExtendTypeForLine(targetParam);

            var result = new IntersectionInfo(sourceExtendType, targetExtendType, intersectPoint);

            return(result);
        }
        private IntersectionInfo IntersectLineAndCurve(Line line, Curve curve, Point3d sorucePoint, ExtendType desireExtendType)
        {
            var points = new Point3dCollection();

            line.IntersectWith(curve, Intersect.ExtendThis, points, IntPtr.Zero, IntPtr.Zero);
            if (points.Count == 0)
            {
                return(null);
            }

            // NOTE: Use Line's GetParameterAtPoint will throw exception if the intersect point is
            // on the line's extension, but LineSegment3d.GetParameterOf is available, so I convert
            // the Line to LineSegment3d here.
            var     lineSegment  = new LineSegment3d(line.StartPoint, line.EndPoint);
            Point3d?nearestPoint = null;
            double? nearestDist  = null;

            foreach (Point3d point in points)
            {
                var param      = lineSegment.GetParameterOf(point);
                var extendType = CurveIntersectUtils.ParamToExtendTypeForLine(param);
                if (extendType != desireExtendType)
                {
                    continue;
                }

                var dist = (point - sorucePoint).LengthSqrd;
                if (nearestDist == null || dist < nearestDist.Value)
                {
                    nearestDist  = dist;
                    nearestPoint = point;
                }
            }

            IntersectionInfo result = null;

            if (nearestPoint != null)
            {
                result = new IntersectionInfo(desireExtendType, ExtendType.None, nearestPoint.Value);
            }
            return(result);
        }