Jump to content
Developer Wiki and Function Reference Links Read more... ×
Sign in to follow this  
nplache

Finding Polygon Center Point

Recommended Posts

I have been searching high and low for this but have lucked out so far.

I have created a polygon using marionette with a number of variables to control the shape, what I would like to be able to do is "analyse" the resulting polygon and find it's center point.

I realise that this could be a potentially complicated request as depending on the shape of the polygon the center point may not be "on surface" for example a "C" shaped object.

There is also the question of center of planar mass (ie balancing point) or simply center point furthest away from all edges.

For my particular use I am only interested in the "on surface" furthest away from all edges, and I am working with a pretty basic shape.

In my mind it seems quite straight forward, I could definitely find a way to "calculate it mathematically" however it would only work for my specific object so I am sure there is a much better and more versatile solution out there.

Any help would be massively appreciated.

Share this post


Link to post

I'm attaching a file with a node, Centroid2D, I haven't taken the time to handle unit conversions (it appears that the VS function doesn't take them into account) so this node in its current state works with Feet/Inches as document units.

If you're working with millimeters, just take out the "/25.4" in the x and y lines, and if you're working with other units, use the factor to convert from millimeters to whichever other document units you're using.

I'll get around to doing error handling on this at a later time.

Hope this helps!

Share this post


Link to post

Hi Marissa,

Thank you for sharing this, perfect tool for finding the 2D center of mass.

Not exactly what I was trying to do but fortunately for my current project it will do the job.

Share this post


Link to post

Hi Marissa & Nic,

1: I thought did the same by 'convert to 3D poly's','get center','locus'. But that doesn't give the same result, I don't understand that.

2: Neither does 'extrude','get gravity center','locus' get the same result???

3: What would be good is to be able to find the largest circle that would fit in a poly and getting the center of that circle.

But I don't know how to solve this.

Share this post


Link to post

I can answer your first two questions quickly, and I'll get to the third one later today after I wake up a bit more :)

1) I'll have to look at Get Center. I don't know who wrote it initially, and I haven't really dove into the logic of it. I think there's a better way to do this anyhow, I'll try to come up with a fix and post it here.

EDIT: I think Get Center works. I'm getting correct results. Can you explain why you think it's incorrect?

2) Get Gravity Center is broken. It's not using the correct function. Again, I'll post it here once I'm sure it's working.

Note on the node once I post it: It probably won't be accurate for Multiple Extrude objects, which is why I haven't already posted it. I've been trying to figure out if I can get it to work for them.

So, for question 3, once I get a better handle on these things, I can hopefully answer this as well for you :)

EDIT2:

Attached file with a correct Gravity Center node. NOTE: This node will not work on polys. Use Get Center from the Poly3D category instead.

Edited by MarissaF

Share this post


Link to post

As the dutch could say: 'Maybe I've put too much hay on my pitchfork'.

The 2D-center I understand, the middle of the bounding box. The improved gravity-center I understand too. But what is the center of the 'get center' node?

I hope you can answer question 3 in the future. Thanks, almost weekend for me.

Share this post


Link to post

So Get Center works with 3D polys and takes the points at each index in order to get the average value of x, y, and z for each point on the poly.

So say you had a 3D poly with 4 points - (0,0,0), (3,0,0), (3,3,3), and (0,3,3).

The Get Center will average all of the x, y, and z values to create the averaged point, i.e.

x = (0 + 3 + 3 + 0) / 4 = 6/4

y = (0 + 0 + 3 + 3) / 4 = 6/4

z = (0 + 3 + 3 + 0) / 4 = 6/4

(This example is super simplistic and produces boring results...)

With more complex polys, it's possible that the point won't be on a planar piece of the poly at all, since it's just averaging the points. You can kind of think of it as finding where the gravitational center of the poly would be? If that makes any sense?

ubbthreads.php?ubb=download&Number=14650&filename=GetCenterExample.PNG

Edited by MarissaF

Share this post


Link to post

So if I would add an index at (1,0,0) that wouldn't change the shape, but would change the outcome of Get Center?

Share this post


Link to post

Correct.

Good point.

I'll see if I can add more logic to this node, I didn't write it originally, but I'll see if there's a way to ignore points that are already on an existing edge and try to modify it.

I didn't even think of that! So big thanks for bringing that situation to my attention!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×