I’m struggling to find centroid of these pieces which lies inside the enclosed curves. How can I do it?
FINDING CENTROID OF PIECES.gh (85.4 KB)
I’m struggling to find centroid of these pieces which lies inside the enclosed curves. How can I do it?
Indeed that’s not the centroid. In any case, given the opportunity - general case - for any BrepFace the point (called sometimes visual center) is approximated via a Quad/OctTree (derived at start from a Bbox per Face and then recursively sub divided).
Hi @archz2
It sounds like you’re after what is also sometimes known as the ‘pole of inaccesibility’
This has come up before in this thread, though I think there wasn’t a working general solution posted then.
I had a look at the open source library Polylabel that @gankeyu mentioned there…
and saw also this conversion to C#
(this is using the same subdivided grid approach that @PeterFotiadis mentions)
With just a few little changes it works in Grasshopper:
Indeed … but is not the Jack for all trades. See so-so results VS the spagetti Crvs (to Polylines)
Plus … hmm …
Note the tolerance setting. 0.15 like you show is much too high
Indeed that code doesn’t support shapes with holes though. I didn’t look at how much change it would need for this.
Ah, it looks like the library already supports shapes with holes.
So it was just a matter of changing the input arrays
polylabel_innaccessibility2.gh (12.0 KB)
This is going to make my cnc layout definisions so much more robust. Thank you so much.
For this example you can use Quadremesh to find the center point or HB straight skeleton from Honeybee addon
cp.gh (55.9 KB)
Somehow I have zero memory of having replied to that topic… This feels so weird.
Yes, this finds the centre of the largest circle.
In some special cases with perfect offsets or parallel lines this largest circle might not be unique though.
For a rectangle anywhere along the long branch of the medial axis satisfies this as these circles are all equal radius.
So if you know the input consists only of constant width strips, an approach like the ones @HS_Kim or @seghierkhaled proposed might be best.
Otherwise perhaps adding a small weighting towards the actual centroid of the shape could help make it less sensitive to bumps and choose among the possible answers for degenerate cases like the rectangle.
Well … get another stupid(*) way to cut(?) the mustard (if it makes any sense at all, but anyway).
Daniel_polylabel_innaccessibility.gh (54.8 KB)
(*) or very stupid.
beautiful approach!!
Thanks a lot. This did it. Actually I wanted to find the centre point in order to place the engraved number tags for fabricating these pieces. This script did the job.
@everyone! Thanks a lot for digging soooo deep! I never thought a seemingly simple query of mine would result in such intense discussion from forum OGs!.