Ejemplo n.º 1
0
        internal static double[][] PtsFromOffsetRectangle(List <Point3d> plist, double offsetdistance)
        {
            double[][] ptz = new double[4][];
            for (int i = 0; i < 4; i++)
            {
                ptz[i]    = new double[2];
                ptz[i][0] = plist[i].X;
                ptz[i][1] = plist[i].Y;
            }

            double[] dblcen = Misc.Centroid(ptz);
            Point3d  cen    = new Point3d(dblcen[0], dblcen[1], 0);

            plist.Add(plist[0]);
            PolylineCurve crv = new PolylineCurve(plist);

            crv.MakeClosed(0.001);
            Curve[]       offsetcr  = crv.Offset(cen, Vector3d.ZAxis, offsetdistance, 0.001, CurveOffsetCornerStyle.None);
            PolylineCurve offsetpl  = offsetcr[0].ToPolyline(0, 0, 0, System.Double.MaxValue, 0, 0.001, 0, 0, true);
            Point3d       offsetpt0 = offsetpl.Point(0);
            Point3d       offsetpt1 = offsetpl.Point(1);
            Point3d       offsetpt2 = offsetpl.Point(2);
            Point3d       offsetpt3 = offsetpl.Point(3);

            return(new double[][] {
                new double[] { offsetpt0.X, offsetpt0.Y },
                new double[] { offsetpt1.X, offsetpt1.Y },
                new double[] { offsetpt2.X, offsetpt2.Y },
                new double[] { offsetpt3.X, offsetpt3.Y }
            });
        }
Ejemplo n.º 2
0
    public void Compute(int gridSize, int x_Ex, int y_Ex, int offsetValue, int offsetValue2, int reduceNum, int minRoomNum, Point3d center
                        , ref List <Rhino.Geometry.Point3d> shapedGrid, ref PolylineCurve shapeCrv, ref Polyline offsetShapeCrv, ref Rectangle3d originalShape)
    {
        var grid        = RhinoWrapper.MakeGrid(x_Ex, y_Ex, gridSize);
        var rectMain    = RhinoWrapper.MakeRect(center, x_Ex, y_Ex, gridSize);
        var rectMainCrv = rectMain.ToPolyline().ToPolylineCurve();

        originalShape = rectMain;

        //減らす部分の四角形をつくるための元のcorner
        var corners = new Rhino.Geometry.Point3d[4];

        for (int i = 0; i < 4; i++)
        {
            corners[i] = rectMain.Corner(i);
        }

        //引くための四角形を作る範囲
        var rectSub  = RhinoWrapper.MakeRect(center, x_Ex, y_Ex, gridSize, offsetValue);
        var rectSub2 = RhinoWrapper.MakeRect(center, x_Ex, y_Ex, gridSize, offsetValue2);


        var populate = RhinoWrapper.RandomPt(rectSub, reduceNum);
        var randPts  = populate.Where(pt => RhinoWrapper.IsInside(pt, rectSub2.ToPolyline()) == false).ToList();

        //点が近いところにあるとオフセットがうまく機能しない。
        for (int i = 0; i < randPts.Count; i++)
        {
            for (int j = 0; j < randPts.Count; j++)
            {
                if (i == j)
                {
                    continue;
                }
                if (randPts[i].DistanceTo(randPts[j]) < gridSize * (minRoomNum + 1))
                {
                    randPts.RemoveAt(j);
                    j--;
                }
            }
        }

        //Reduce Rectsを作ってる
        var reduceRects = new List <Rhino.Geometry.PolylineCurve>();
        var planeXY     = new Rhino.Geometry.Plane(Point3d.Origin, Vector3d.ZAxis);

        for (int i = 0; i < randPts.Count; i++)
        {
            var pc         = new Rhino.Geometry.PointCloud(corners);
            int closestIdx = pc.ClosestPoint(randPts[i]);
            var reduceRect = new Rectangle3d(planeXY, randPts[i], corners[closestIdx]);
            var polyCrv    = reduceRect.ToPolyline().ToPolylineCurve();
            reduceRects.Add(polyCrv);
        }


        var shape = Curve.CreateBooleanDifference(rectMainCrv, reduceRects, 0.1);

        offsetShapeCrv = null;
        //正四角形でない形がでたとき
        if (shape.Length > 0)
        {
            shape[0].TryGetPolyline(out Polyline polyShape);

            //ref
            shapedGrid = grid.Where(pt => RhinoWrapper.IsInside(pt, polyShape)).ToList();

            //ref
            shapeCrv = polyShape.ToPolylineCurve();

            //ref
            var plane = new Rhino.Geometry.Plane(AreaMassProperties.Compute(shapeCrv).Centroid, Vector3d.ZAxis);
            shapeCrv.Offset(plane, (-gridSize * minRoomNum), 1, CurveOffsetCornerStyle.Sharp)[0].TryGetPolyline(out offsetShapeCrv);
            if (offsetShapeCrv == null)
            {
                offsetShapeCrv = new Rectangle3d(plane, 1, 1).ToPolyline();
            }
        }
        else//正四角形が残ったとき。(ひくためのRectangleができない)
        {
            shapedGrid = grid.Where(pt => RhinoWrapper.IsInside(pt, rectMainCrv.ToPolyline())).ToList();

            //ref
            shapeCrv = rectMainCrv.ToPolyline().ToPolylineCurve();

            //ref
            var plane = new Rhino.Geometry.Plane(AreaMassProperties.Compute(shapeCrv).Centroid, Vector3d.ZAxis);
            shapeCrv.Offset(plane, (-gridSize * minRoomNum), 1, CurveOffsetCornerStyle.Sharp)[0].TryGetPolyline(out offsetShapeCrv);
            if (offsetShapeCrv == null)
            {
                offsetShapeCrv = new Rectangle3d(plane, 1, 1).ToPolyline();
            }
        }
    }
Ejemplo n.º 3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Plane  plane     = new Plane();
            string text      = "";
            double size      = 5;
            int    justify   = 0;
            string font      = "";
            bool   bold      = false;
            double offsetDis = 0;

            DA.GetData("Location", ref plane);
            DA.GetData("Text", ref text);
            DA.GetData("Size", ref size);
            DA.GetData("Justification", ref justify);
            DA.GetData("Font", ref font);
            DA.GetData("Bold", ref bold);
            DA.GetData("OffsetDistance", ref offsetDis);

            if (justify < 0 || justify > 8)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid Justification.Only 0-8 are allowed.");
                justify = 4;
            }

            TextJustification justification = TextJustification.MiddleCenter;

            if (justify == 0)
            {
                Message       = "BottomLeft";
                justification = TextJustification.BottomLeft;
            }
            else if (justify == 1)
            {
                Message       = "BottomCenter";
                justification = TextJustification.BottomCenter;
            }
            else if (justify == 2)
            {
                Message       = "BottomRight";
                justification = TextJustification.BottomRight;
            }
            else if (justify == 3)
            {
                Message       = "MiddleLeft";
                justification = TextJustification.MiddleLeft;
            }
            else if (justify == 4)
            {
                Message       = "MiddleCenter";
                justification = TextJustification.MiddleCenter;
            }
            else if (justify == 5)
            {
                Message       = "MiddleRight";
                justification = TextJustification.MiddleRight;
            }
            else if (justify == 6)
            {
                Message       = "TopLeft";
                justification = TextJustification.TopLeft;
            }
            else if (justify == 7)
            {
                Message       = "TopCenter";
                justification = TextJustification.TopCenter;
            }
            else if (justify == 8)
            {
                Message       = "TopRight";
                justification = TextJustification.TopRight;
            }


            TextEntity t = new TextEntity();

            t.Plane          = plane;
            t.PlainText      = text;
            t.DimensionScale = size;
            t.Font           = Rhino.DocObjects.Font.InstalledFonts(font)[0];
            t.Justification  = justification;
            t.SetBold(bold);
            List <Curve> curves = new List <Curve>(t.Explode());

            List <Point3d> boxCorner = new List <Point3d>();

            foreach (Curve crv in curves)
            {
                foreach (Point3d pt in crv.GetBoundingBox(plane).GetCorners())
                {
                    boxCorner.Add(pt);
                }
            }

            Box box = new Box(plane, new BoundingBox(boxCorner));

            Point3d[] corners = box.GetCorners();
            Point3d[] pts     = new Point3d[5] {
                corners[0], corners[1], corners[2], corners[3], corners[0]
            };

            PolylineCurve polyCrv = new PolylineCurve(pts);
            Curve         bound;

            if (offsetDis == 0)
            {
                bound = polyCrv;
            }
            else
            {
                bound = polyCrv.Offset(plane, offsetDis, GH_Component.DocumentTolerance(), CurveOffsetCornerStyle.Round)[0];
            }



            DA.SetDataList("Curve", curves);
            DA.SetData("Bound", bound);
        }