Exemple #1
0
        /// <summary>
        /// 求线段的相交点
        /// </summary>
        /// <param name="curve">直线</param>
        /// <param name="isLineSegment">是否为线段</param>
        /// <param name="epsilon">误差值</param>
        /// <returns></returns>
        public Vector3D Intersect(Line3D curve, bool isLineSegment = true, double epsilon = Extension.SMALL_NUMBER)
        {
            var a = 0d;
            var b = 0d;

            epsilon = epsilon < 0 ? Extension.SMALL_NUMBER : epsilon;
            var intersect = LineLine(this, curve, out a, out b, epsilon);

            if (!intersect)
            {
                return(null);
            }
            var isOnLine = a >= -epsilon && a <= 1 + epsilon && b >= -epsilon && b <= 1 + epsilon;

            if (isLineSegment && !isOnLine)
            {
                return(null);
            }
            var p1  = Evaluate(a);
            var p2  = curve.Evaluate(b);
            var dis = p1.Distance(p2);

            if (dis < epsilon)
            {
                return(p1);
            }
            return(null);
        }
Exemple #2
0
        private List <Line3D> GetLinesFromIntersectPoints2(List <Vector3D> intersectPoints, List <Line3D> faceEdges)
        {
            List <Line3D>   interLines         = new List <Line3D>();
            List <Vector3D> newIntersectPoints = new List <Vector3D>();

            foreach (var point in intersectPoints)
            {
                if (newIntersectPoints.Contains(point, new Vector3DEqualityComparer()))
                {
                    continue;
                }
                newIntersectPoints.Add(point);
            }
            newIntersectPoints = newIntersectPoints.OrderByXYZ();
            for (int i = 0; i < newIntersectPoints.Count - 1; i++)
            {
                Line3D   temp        = new Line3D(newIntersectPoints[i], newIntersectPoints[i + 1]);
                Vector3D middlePoint = temp.Evaluate(0.5);
                //判断点是否在多边形区域的内部或者边上
                bool isPointInRegion = IsPointInsideRegion(middlePoint, faceEdges) || IsPointInRegionOutLine(middlePoint, faceEdges);
                if (isPointInRegion)
                {
                    interLines.Add(temp);
                }
            }
            return(interLines);
        }