Convert closed polygon to polyline

I seek your help scripting a code to convert closed polygon with many vertices to single polyline with only two vertices start and end. (from the red one to the green one in the snip below)

So you’re looking for the longest straight line enclosed within a polygon that travels through the polygon’s centroid?

Exactly, as shown here, if I have the white border polyline I need to convert it to the red center polyline

You can use the node Surface.GetIsoLine with the parameter 0.5 to get the 2 central lines by Isoline U and V. as the photo above. Then, you use 1 more node to compare the length of the curve to collect the longer curve, as the central longer line you want.

I’m trying to start something here, although I’m not sure if this is the right approach.

If I get 4 points for the border, How can I get the middle points between 0,1 & 2,3 ?

I don’t know what is your input. So I will separate it into 2 cases:
The first case, your object is polylines:

The 2nd case as I mentioned in my 1st comment that you have a surface:

  • I use the node Surface.GetIsoline to get 2 center lines => Comparing 2 center lines to get the longer center line (photo below).

I’m not sure if I can understand your point, but I wanna highlight that I’m not dealing with surfaces anyway, what I have are polylines

test.dyn (31.8 KB)

You mean something like this?

Select rectangle / polygon > Needs to be rectangle shaped(!). Find out shortest sides, create new line from middle point to middle point of these shortest lines.

Assuming that you have rectangles only, and following your logic, maybe this will help?


Neat concept @Assem.Daaboul

1 Like