Ashish,
The generalized algorithm Pg = Integral( r.m(dr))/Integral(dm)
where r is a distance vector and m (dr) is mass density.
For simple primitives like Sphere/Cone/Cylinder/Box it is the center of
the volume itself if you assume uniform distribution of mass , which your
description sounds like.
Here are some formulas that will give you the COG for simple primitives
for the above case.
Sphere : Pg = r0 where
r0 = vector of center of sphere
Cylinder: Pg = r0 + (r1 - r0)/2 where
r0 = vector of center of lower circle
r1 = vector of center of upper circle
Cone: Pg = r0 + delta*unit(r1-r0) where
delta = (h*sqr(r0)/2 + sqr(r1-r0)*cube(h)/4 +
2*(r1-r0)*r0*sqr(h) /3) / (sqr(r0) + sqr(r1-r0)*sqr(h)/3 + (r1-r0)*r0/h)
r0 = vector of center of smaller circle of cone
r1 = vector of center of larger circle of cone
unit(r1-r0) = unit vector from r0 to r1
h = distance from r0 to r1 (height of cone)
For the familiar case of a cone with no frustum(
r0 = 0 ) this reduces
to Pg = r0 + 3*h/4
Box: Pg = centre of box
Anand Pillai
DELMIA Solutions India.
680, 8th Main, JP NAGAR II Phase,
Bangalore 560 078.
Tel: +91-80- 658 9858/59 Fax: +91-80- 658 9855.
[EMAIL PROTECTED]
Yuri Nikishkov <[EMAIL PROTECTED]> on 06/23/2001 04:09:19 AM
Please respond to Discussion list for Java 3D API <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc: (bcc: Anand PILLAI/dassault-systemes)
Subject: Re: [JAVA3D]
>Can somebody tell me how to find out the center of
>gravity of primitives in Java 3D API like cone,
>cylinder, sphere etc. I should be able to get the
>center of gravity of primitives at any point on the
>screen i.e if I have moved primitive from one place to
>another, I should be able to get center of gravity at
>that particular point.
Center of gravity is weight averaged body coordinate so it is x0 =
Integral{m(x)dv}/M, where m(x) is mass density, M is total mass, x is vector
coordinate over the body and volume integral is taken over the body, of
course. From your description it is fare to suppose that your primitives
have constant density and volume does not depend on the coordinate, so the
formula becomes x0 = Integral{dv}/V, where V is the volume. You can compute
it for every primitive in its local coordinates separately (try sphere
first) and then apply primitive local-to-world transformation to the
precomputed center of gravity.
- Yuri
Title: RE: [JAVA3D]
>Can somebody tell me how to find out the center of
>gravity of primitives in Java 3D API like cone,
>cylinder, sphere etc. I should be able to get the
>center of gravity of primitives at any point on the
>screen i.e if I have moved primitive from one place to
>another, I should be able to get center of gravity at
>that particular point.
Center of gravity is weight averaged body coordinate so it is x0 = Integral{m(x)dv}/M, where m(x) is mass density, M is total mass, x is vector coordinate over the body and volume integral is taken over the body, of course. From your description it is fare to suppose that your primitives have constant density and volume does not depend on the coordinate, so the formula becomes x0 = Integral{dv}/V, where V is the volume. You can compute it for every primitive in its local coordinates separately (try sphere first) and then apply primitive local-to-world transformation to the precomputed center of gravity.
- Yuri
