Center of Gravity

podperson

Well-known member
Center of Gravity

This script finds the area of a selected set of faces and sets the pivot to their "center of gravity" (where area is treated as mass)

This is a Tool script and it requires C3D 5.0 or later.

Update

Now works regardless of rotation and scale of the polygon object.

If nothing else, it's very good for setting the pivot of a mesh to the center of a face (e.g. if you want a door to rotate around one side).
 

Attachments

  • Screen shot 2009-10-23 at 2.20.31 PM.png
    Screen shot 2009-10-23 at 2.20.31 PM.png
    56.1 KB · Views: 985
  • center of gravity.js.zip
    1.6 KB · Views: 685
Last edited:

Micmac

New member
This is great PodPerson, just what I asked for.


Thanks a lot!


Now, could you also give the volume of the object?

Mic
 

podperson

Well-known member
Volume seems to be a lot harder. The center of mass of a tetrahedron is easy (average of the vertices :) ) -- as is the volume -- but figuring out how to decompose an object into tetradhedra is hard (a lot of modeling programs aren't exactly sure where the interior of objects are, or if they're in fact solids -- just try playing with C3D's booleans for a bit and see for yourself).

My script takes advantage of C3D's internal triangulation -- so it will fail when C3D's triangulation fails (e.g. on some non-convex n-gons). Figuring out the area of an n-gon is non-trivial when the ngon itself is not very rigorously defined. So -- short answer -- no :)
 

Micmac

New member
Volume seems to be a lot harder. The center of mass of a tetrahedron is easy (average of the vertices :) ) -- as is the volume -- but figuring out how to decompose an object into tetradhedra is hard (a lot of modeling programs aren't exactly sure where the interior of objects are, or if they're in fact solids -- just try playing with C3D's booleans for a bit and see for yourself).

My script takes advantage of C3D's internal triangulation -- so it will fail when C3D's triangulation fails (e.g. on some non-convex n-gons). Figuring out the area of an n-gon is non-trivial when the ngon itself is not very rigorously defined. So -- short answer -- no :)

OK

But thanks anyway. This is great!

Mic
 

crgreen

Member
I've updated the center of gravity script to calculate the center of volume correctly, and posted it on my site.

http://loewald.com/c3dbook/Scripts/Center-of-Gravity/

(This is because the 3d weasel I printed out tips over all the time, and I want the next version to stand stably on its own feet :) )


I love this script - and incorporated it into my own to do a multiple of objects at once. However, it freaks out - that is, it is unreliable - when used on 2 dimensional objects (like a single poly). This is probably not surprising, but it would be nice to have something in the code to account for this.
If you want to see what happens, just make a flat object, launch the script and hit the "Set Center of Gravity" button over and over again. You'll see it jump to seemingly random points just outside of (not actually on) the object.
 
Top