I am trying to implement a method that takes 2 shape/body pairs and combines them into 2 shapes 1 shared body. My approach would be as follows:
1. Find the new center of mass using the sum of the first mass moments.
2. Calculate the new shape offsets based on the new cm
3. Reuse one of the bodies, setting new mass to be (m1 + m2) and new moment of inertia to be (i1 + i2)
4. Remove and Free the other body
5. Point both shapes at the new body (shape->body = new_body)
Does this approach seem plausible especially the calculation of the new moment of inertia?
Combining 2 Shapes/Bodies into one body
-
- Posts: 90
- Joined: Tue Aug 04, 2009 9:53 am
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Combining 2 Shapes/Bodies into one body
Yep. You are basically just doing a weighted average to find the new CoG and use the parallel axis theorem to find and sum the new moments of inertia given the offsets to the old bodies' CoGs.
Calculating new shape parameters would have to be handled on a case by case basis, but shouldn't be too hard.
Calculating new shape parameters would have to be handled on a case by case basis, but shouldn't be too hard.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 90
- Joined: Tue Aug 04, 2009 9:53 am
- Contact:
Re: Combining 2 Shapes/Bodies into one body
Thanks slembcke, hmmmm are you saying that the new moment is not simply a sum of the old moments? I'll try to figure out that theorem (sometimes I suck at math equations).
I started calculating the new shape parameters for circles only using the offset property (it works!); I suppose for segments I'd be offsetting the endpoints and for poly's I'd be offsetting all the vertices.....
I started calculating the new shape parameters for circles only using the offset property (it works!); I suppose for segments I'd be offsetting the endpoints and for poly's I'd be offsetting all the vertices.....
-
- Posts: 90
- Joined: Tue Aug 04, 2009 9:53 am
- Contact:
Re: Combining 2 Shapes/Bodies into one body
Heres what I decided to go with, it seems right even though this particular example is for a polygon made up of triangles:
http://lab.polygonal.de/2006/08/17/calc ... x-polygon/
Pretty much I do this equation:
where b1 and b2 are the old bodies, and the offset variables are just the difference vector between the new center of mass and the old ones.
http://lab.polygonal.de/2006/08/17/calc ... x-polygon/
Pretty much I do this equation:
Code: Select all
cpFloat moi = ((b1->i + b1->m*cpvdot(offset1, offset1)) +
(b2->i + b2->m*cpvdot(offset2, offset2)));
Who is online
Users browsing this forum: No registered users and 11 guests