[Bf-committers] Cursor to center of mass
umminom at gmail.com
Thu Nov 22 05:37:57 CET 2012
I'm aiming a bit lower so I prefer to attack the mechanics of the problem.
Limiting the calculation by actual volume to when it makes sense would be
nice, but detecting overlaps etc. seems overkill.
Here's later code which does it basically two ways, one is the tetrahedron
and the other is polygon centroid.
On Thu, Nov 22, 2012 at 3:46 AM, bjornmose at gmx.net <bjornmose at gmx.net>wrote:
> Did you check against 'non orientable surfaces'?
> Möbius strip
> Klein Bottle
> I doubt the algorithm stands with that...
> As far as I remember those objects have no defined volume?
> As : how would you like to make a cylinder from a Möbius strip?
> You can always create a bounding object .. like in triangulating the
> circle ..
> alas .. it will be getting close enough, which might be sufficient for
> blender, and might be nice to have..
> Well if blender refuses to create such geometry .. bad enough
> Mathematica and friends can.
> Well I think you should check the definition of 'closed' and require
> 'orientable' and it will work out fine.
> so much for that
> one more .. your algorithm assumes homogeneous density .. how realistic
> is that ? .. for all cases ?
> Is a balloon filled with air the same as the balloon filled with water?
> As the mass is on the surface versus the mass is in the volume ?
> Am 21.11.2012 04:30, schrieb Ummi Nom:
> > Hi!
> > I've written some center of mass calculations in python for closed
> > but there is an issue with using tessfaces in my code; I run mesh.update
> > with tessfaces=True but when I loop over mesh.tessfaces there are only 6
> > faces in default scene cube so the center of mass is offset.
> > It seems to work when the mesh is triangulated
> > http://www.pasteall.org/37396/python
> > # Code
> > import mathutils
> > from mathutils import *
> > import bpy
> > tess_count = 0
> > # Handle tri as a tetrahedron with fourth point at origo
> > def handleTri(v1, v2, v3):
> > global tess_count
> > tess_count = tess_count + 1
> > temp = (v3-v1).cross(v2-v1)
> > nor = temp.normalized()
> > area = 0.5*temp.dot(nor)
> > vol = area*nor.dot(v1)/3.0
> > centroid = (v1+v2+v3)/4.0
> > return (centroid, vol)
> > for me in bpy.data.meshes:
> > me.update(calc_tessface=True)
> > sumc= Vector()
> > summ = 0
> > for f in me.tessfaces:
> > v1 = Vector(me.vertices[f.vertices].co)
> > v2 = Vector(me.vertices[f.vertices].co)
> > v3 = Vector(me.vertices[f.vertices].co)
> > centroid, mass = handleTri(v1, v2, v3)
> > sumc += centroid * mass
> > summ += mass
> > print(tess_count)
> > print(sumc/summ)
> > _______________________________________________
> > Bf-committers mailing list
> > Bf-committers at blender.org
> > http://lists.blender.org/mailman/listinfo/bf-committers
> Bf-committers mailing list
> Bf-committers at blender.org
More information about the Bf-committers