Rectangle3d explode into 4 segments (C#)

Hi, Is there a way I can explode the rectangle into its 4 parts using C# rhino/Grasshopper?

Thanks

You could turn the rectangle into a polyline and then access the polyline segments, which are four lines.

Thanks it worked

@diff-arch @Alca Does it work in GH Python? It did not work for me. But it gave 5 points. The code I wrote is placed below.

rect1 = rg.Rectangle3d(plane1, point1, point2)
polyline1 = rg.Rectangle3d.ToPolyline(rect1)

Thank in advance vijesh

That’s normal. A closed polyline, like your rectangle, is defined by a start and end point that are identical.

Thank you for your quick reply. I was expecting the segments. I have found the command.

polyline1 = rg.Rectangle3d.ToPolyline(rect1)
polylineseg1 = rg.Polyline.GetSegments(polyline1)
polylineseg2 = polylineseg1[1]

I am finding it difficult to find any references, especially in GHPython. Are there any books for reference?

Thank you very much. vijesh

A polyline is like a list or an array of points, not a curve. Rhino.Geometry.Polyline.GetSegments() simply constructs the collection of lines that connect the points for you. Previously these didn’t exist.

If you want a curve as output, you can do this:

polyline1 = rg.Rectangle3d.ToPolyline(rect1)
a = polyline1.ToPolylineCurve()

There’s the documentation.

1 Like