Пример #1
0
        public static List <Line3D> GetIntersection(this Polygon3D polygon, Plane3D plane)
        {
            var points = new List <WM.Point3D>(2);

            var count = polygon.Count;

            for (var i = 1; i < count; ++i)
            {
                var l0 = polygon[i - 1];
                var l  = polygon[i] - l0;
                var d  = WM.Vector3D.DotProduct(l, plane.NormalVector);
                if (!d.IsZero(1e-12))
                {
                    d = GetIntersecionDistance(l0, l, plane);
                    if (d.IsGreaterOrEqual(0) && d.IsLesserOrEqual(1))                     // d >= 0 && d <= 1
                    {
                        var intersection = d * l + l0;
                        points.Add(intersection);
                    }
                }
            }

            RemoveDuplicates(points);
            count = points.Count;
            // System.Diagnostics.Debug.Assert(!(count > 2 && count % 2 != 0));
            var lines = new List <Line3D>(count / 2);

            for (var i = 1; i < count; i += 2)
            {
                var line = new Line3D(points[i - 1], points[i]);
                lines.Add(line);
            }

            return(lines);
        }
Пример #2
0
 public static void Move(this Polygon3D p, WM.Vector3D dir)
 {
     for (var i = p.Count - 1; i >= 0; --i)
     {
         p[i] += dir;
     }
 }
Пример #3
0
        public static Polygon3D Convert(IPolyLine3D polyline)
        {
            var points = new List <IPoint3D>(polyline.Count);

            GeomOperation.ConvertPolylineToPointList(polyline, points, false, 5);
            var polygon = new Polygon3D(points.Select(p => p.ToMediaPoint()));

            return(polygon);
        }
Пример #4
0
        public static List <Line3D> GetIntersection(this Polygon3D p1, Polygon3D p2)
        {
            var p1Plane = p1.GetPlane();
            var p2Plane = p2.GetPlane();

            ////if (WM.Vector3D.CrossProduct(p1Plane.NormalVector, p2Plane.NormalVector).LengthSquared.IsZero())
            ////{
            ////	// polygons are parallel, use clipper
            ////	var axisX = (p1[1] - p1[0]).ToIndoVector3D().Normalize;
            ////	var axisZ = p1Plane.NormalVector.ToIndoVector3D();
            ////	var axisY = (axisX * axisZ).Normalize;
            ////	var lcs = new Matrix44(p1[0], axisX, axisY, axisZ);
            ////	var p12D = new Polygon2D(p1.Select(p =>
            ////	{
            ////		var pt = lcs.TransformToLCS(p);
            ////		return new Point(pt.X, pt.Y);
            ////	}));
            ////	var p22D = new Polygon2D(p2.Select(p =>
            ////	{
            ////		var pt = lcs.TransformToLCS(p);
            ////		return new Point(pt.X, pt.Y);
            ////	}));
            ////	var clipper = new ClipperController();
            ////	clipper.Add(p12D, ClipperLib.PolyType.ptSubject);
            ////	clipper.Add(p22D, ClipperLib.PolyType.ptClip);
            ////	var inters2 = clipper.IntersectionPolygons();
            ////	var xxx = new List<Line3D>();
            ////	foreach (var i in inters2)
            ////	{
            ////	}

            ////	throw new NotImplementedException();
            ////}

            var p1Inters = GetIntersection(p1, p2Plane);
            var p2Inters = GetIntersection(p2, p1Plane);

            List <Line3D> inters = GetIntersection(p1Inters, p2Inters);

            if (inters.Count > 0)
            {
                var item0 = inters[0];
                if (item0.P1.IsEqual(item0.P2, 1e-6))                 // line points are the same
                {
                    return(new List <Line3D>());
                }
            }

            return(inters);
        }