Example #1
0
        public static List <List <Point3d> > CalculateSamplePoints(List <Line> lines, PolylineCurve polyline, double percision)
        {
            Point3d pointStart = polyline.GetBoundingBox(true).Min;
            Point3d pointEnd   = polyline.GetBoundingBox(true).Max;

            int number      = (int)Math.Ceiling((pointEnd.X - pointStart.X) / percision);
            var usingPoints = new List <List <Point3d> >();

            for (int i = 0; i < lines.Count; i++)
            {
                List <Point3d> stoeryPoints = new List <Point3d>();
                for (int j = 0; j < number; j++)
                {
                    var plane    = new Plane(new Point3d(pointStart.X + j * percision, 0, 0), Vector3d.XAxis);
                    var curve    = lines[i].ToNurbsCurve();
                    var crossing = Intersection.CurvePlane(curve, plane, 0.001);
                    if (crossing != null && crossing.Count == 1)
                    {
                        stoeryPoints.Add(crossing[0].PointA);
                    }
                }
                usingPoints.Add(stoeryPoints);
            }
            return(usingPoints);
        }
        private IntersectResult Intersect2Curves(Curve a, Curve b)
        {
            int             clipperPrecision = 100;
            IntersectResult result           = new IntersectResult();

            if (Curve.PlanarCurveCollision(a, b, Plane.WorldXY, 0.001f))
            {
                Clipper clipper  = new Clipper();
                Path    subjectA = CurveToPath(a, clipperPrecision);
                Path    subjectB = CurveToPath(b, clipperPrecision);
                Paths   solution = new Paths();

                clipper.AddPath(subjectA, PolyType.ptClip, true);
                clipper.AddPath(subjectB, PolyType.ptSubject, true);

                clipper.Execute(ClipType.ctIntersection, solution, PolyFillType.pftNonZero, PolyFillType.pftNonZero);

                if (solution.Count > 0)
                {
                    result.intersect = true;
                    PolylineCurve pl = PathToPolyline(solution[0], clipperPrecision);
                    result.unionCurve = pl;

                    Point3d minPoint = pl.GetBoundingBox(false).Min;
                    Point3d maxPoint = pl.GetBoundingBox(false).Max;

                    if (maxPoint.X - minPoint.X > maxPoint.Y - minPoint.Y)
                    {
                        result.reboundingVector = new Vector2d(0, -(maxPoint.Y - minPoint.Y));
                        if (AreaMassProperties.Compute(a).Centroid.Y > AreaMassProperties.Compute(b).Centroid.Y)
                        {
                            result.reboundingVector.Y *= -1;
                        }
                    }
                    else
                    {
                        result.reboundingVector = new Vector2d(-(maxPoint.X - minPoint.X), 0);
                        if (AreaMassProperties.Compute(a).Centroid.X > AreaMassProperties.Compute(b).Centroid.X)
                        {
                            result.reboundingVector.X *= -1;
                        }
                    }
                }
            }
            else
            {
                result.intersect        = false;
                result.reboundingVector = Vector2d.Unset;
                result.unionCurve       = null;
            }
            return(result);
        }
Example #3
0
        //get plane and bounding box from points
        public static Plane polylineBbox(List <Point3d> Points, out Box Bbox)
        {
            Polyline boundingCrv = new Polyline(Points);

            boundingCrv.Add(Points[0]);
            Line  longest = boundingCrv.SegmentAt(0);
            Plane bPlane  = new Plane();

            for (int i = 0; i < boundingCrv.SegmentCount; i++)
            {
                if (longest.Length < boundingCrv.SegmentAt(i).Length)
                {
                    longest = boundingCrv.SegmentAt(i);
                    if (i == 0)
                    {
                        bPlane = new Plane(longest.From, longest.Direction, -boundingCrv.SegmentAt(boundingCrv.SegmentCount - 1).Direction);
                    }
                    else
                    {
                        bPlane = new Plane(longest.From, longest.Direction, -boundingCrv.SegmentAt(i - 1).Direction);
                    }
                }
            }
            PolylineCurve boundingPolyCrv = boundingCrv.ToPolylineCurve();

            boundingPolyCrv.GetBoundingBox(bPlane, out Bbox);
            bPlane.Origin = (longest.To - longest.From) / 2 + longest.From;
            return(bPlane);
        }
Example #4
0
        //get plane and bounding box from polyline
        public static Plane polylineBbox(Polyline BoundingCrv, out Box Bbox)
        {
            Line  longest = BoundingCrv.SegmentAt(0);
            Plane bPlane  = new Plane();

            for (int i = 0; i < BoundingCrv.SegmentCount; i++)
            {
                if (longest.Length <= BoundingCrv.SegmentAt(i).Length)
                {
                    longest = BoundingCrv.SegmentAt(i);
                    if (i == 0)
                    {
                        bPlane = new Plane(longest.From, longest.Direction, -BoundingCrv.SegmentAt(BoundingCrv.SegmentCount - 1).Direction);
                    }
                    else
                    {
                        bPlane = new Plane(longest.From, longest.Direction, -BoundingCrv.SegmentAt(i - 1).Direction);
                    }
                }
            }
            PolylineCurve boundingPolyCrv = BoundingCrv.ToPolylineCurve();

            boundingPolyCrv.GetBoundingBox(bPlane, out Bbox);
            bPlane.Origin = (longest.To - longest.From) / 2 + longest.From;
            return(bPlane);
        }
        // Rh Capture
        public Base PolylineToSpeckle(PolylineCurve poly, string units = null)
        {
            var u = units ?? ModelUnits;

            RH.Polyline polyline;

            if (poly.TryGetPolyline(out polyline))
            {
                var intervalToSpeckle = IntervalToSpeckle(poly.Domain);
                if (polyline.Count == 2)
                {
                    var polylineToSpeckle = new Line(PointsToFlatArray(polyline), u)
                    {
                        domain = intervalToSpeckle
                    };
                    polylineToSpeckle.length = polyline.Length;
                    var box = new RH.Box(poly.GetBoundingBox(true));
                    polylineToSpeckle.bbox = BoxToSpeckle(box, u);
                    return(polylineToSpeckle);
                }

                var myPoly = new Polyline(PointsToFlatArray(polyline), u);
                myPoly.closed = polyline.IsClosed;

                if (myPoly.closed)
                {
                    myPoly.value.RemoveRange(myPoly.value.Count - 3, 3);
                }

                myPoly.domain = intervalToSpeckle;
                myPoly.bbox   = BoxToSpeckle(new RH.Box(poly.GetBoundingBox(true)), u);
                myPoly.length = poly.GetLength();
                return(myPoly);
            }

            return(null);
        }
Example #6
0
        public List <Point3d> VoxelizePolyline(int CO, PolylineCurve Crv, double Sx, double Sy, double Sz)
        {
            //A = MeshToTriangles(M)
            Vector3d    VSize = new Vector3d(Sx, Sy, Sz);
            BoundingBox RBBox = Crv.GetBoundingBox(false);
            BoundingBox ZBBox = RBBox_to_ZBBox(RBBox, VSize);
            //A = ZBBox
            List <Point3d> gridpoints = BBoxToVoxels(ZBBox, VSize);
            //B = Gridpoints
            List <Mesh>    Intargets = new List <Mesh>();
            List <Point3d> Voxels    = new List <Point3d>();

            int[]          Facets         = null;
            Mesh           Intarget       = null;
            List <Point3d> Crv_NearPoints = NearPoints(gridpoints, Crv, VSize.Length / 2);

            //print(Crv_NearPoints.count)
            foreach (Point3d gridpoint in Crv_NearPoints)
            {
                if (CO == 26)
                {
                    Intarget = LineTarget26_Connected(gridpoint, VSize);
                }
                else if (CO == 6)
                {
                    Intarget = LineTarget6_Connected(gridpoint, VSize);
                }
                else
                {
                    throw new Exception("connectivity target undefined!");
                }
                if (Rhino.Geometry.Intersect.Intersection.MeshPolyline(Intarget, Crv, out Facets).Length > 0)
                {
                    Voxels.Add(gridpoint);
                }
            }
            //B = Intargets
            return(Voxels);
        }