Find regular polygon inside


I’m trying to find a regular polygon (all inside angles are equal in measure - 90º,180º,270º…) by finding right triangles around the perimeter. The definition is working good but depending on how my initial segments list starts the subdivision can change, so I needed to add a shift list initially to manually choose the best seed to give me the minimum triangles as result.



Different seed:

(different result, still a good solution, but high number of triangles)

I tried out using Manhattan Distance only but it failed because if a rotate my polygon the triangles will also change which does not work for me. My goal is how get the minimum of triangles no matter how ortogonal is my input ending up with a regular polygon inside.

I appreciate any kind of help, thank you!

findRegularPolygon.3dm (40.0 KB) (27.2 KB)

It looks to me as though each edge that is not parallel or at right-angles to the axis system for your main polyhedron results in a triangle. If you want to minimize the number of triangles, you need to find an axis system that maximizes the number of edges that are parallel or at right angles to it. All remaining edges become triangles.

Or am I missing something?

1 Like

I.e. For each edge, count the number of other edges that are parallel or at right angles to it; find the edge with the highest count; make triangles from all edges that are not parallel or at right angles to that edge.

1 Like

Hi @bob.h.mackay !

Thank you very much for your reply and yes, you’re right! At the begging I tried count internal angles equal to 90-180-270º and use what is not but it didn’t work because for me the way to solve would be using recurvive and I really don’t want to use anemone or something.

It seems working good but I’m not sure if I understood correctly because how can I count parallel or right angles to an edge if I have continuous segments so the way to check this is getting 3 edges (the middle one set the angles to the others), right?

I have tried to find the parallel / right angles through edges intersections:

I.e: an example what I looking foward. In this way I could avoid a bunch of unnecessary right triangles

Thank you/all in advance for the support!
p.s. I’ve break down my .gh file into explanations to make it more elucidative.

findRegularPolygon R01.3dm (42.6 KB)
findRegularPolygon (40.5 KB)

I had a play with this. My approach was to try to find the main axis of your polyhedron, by looking at the angles of all the edges making up the shape, and finding the commonest one.

My first attempt used each edge as a vector, which is fairly elegant, but then I remembered that you wanted to count 90/180/270/260 as equivalent, so I had to fall back to angles. There must be a better way to find “the most frequent value in a list” than using the ‘valence’ output of ‘cull duplicates’, but I don’t know what it is. The result is a horrid conversion of angles to points and back again. Sigh.

Anyway, perhaps this is helpful. (18.6 KB)