views:

689

answers:

3

This is a similar question to this one here.

Given a list of 3D coordinates that define the surface( Point3D1, Point3D2, Point3D3, and so on), how to calculate the centroid of the surface?

In 2D the computation is given by the following formula:

alt text

alt text

alt text

What about the 3D analogue?

+1  A: 

If it's a planar surface, you can transform to a coordinate system local to the plane, calculate the centroid using the formulas you presented, and then transform back to get its coordinates in 3D space.

duffymo
Besides coordinate transformation, is there a direct method? If no, I would appreciate a formula on how to transform coordinate.
Ngu Soon Hui
+2  A: 
KennyTM
**Since ratio of area of 2D figures is constant under parallel projection, you may want to choose a unit vector (e.g. z) not parallel to the plane, the treat (vi − v0) × (vi+1 − v0) · z as the area**. Can be more explicit on that part?
Ngu Soon Hui
Take z = (v1-v0) × (v2-v0), for example.
AVB
@KennyTM, I think your formulation is good. But is there anyway to eliminate the special dependencies on the `v0`? Much like how the above 2D centroid computation is formulated. I'm sure with some tweaking it's possible to do it.
Ngu Soon Hui
@Ngu: Any v0 is fine. Or you could use tom10's solution (http://stackoverflow.com/questions/2355931/compute-the-centroid-of-a-3d-planar-polygon/2360507#2360507)
KennyTM
@KennyTM, what I mean is, I don't want any `v0` or other subscript ( such as 1,2,3) to appear in my euqation. Or, to put it other way, the equation must involve only `vi`, `vi+1`, `vi-1` etc. No special `v0`, `v1` or `v2`. Is it possible to construct such an equation?
Ngu Soon Hui
@Ngu: Why? ____
KennyTM
@KennyTM, any special treatment of any special coordinate points seems not general enough to me.
Ngu Soon Hui
@Ngu: This is completely general. v0 can be chosen to be any vertex.
KennyTM
@Kenny, there is another thing that worries me in your formulation, namely, you are doing this `| (vi − v0) × (vi+1 − v0) | ÷ 2` and later check for the concavity, are you saying that if the area is concave we should minus it out?
Ngu Soon Hui
@Ngu: Yes. If you're sure the polygon doesn't parallel to the z-axis you can use `(vi − v0) × (vi+1 − v0) · z` also, and it's much more efficient.
KennyTM
A: 

Just use the equations that you have twice, but the second time swap in z for y.

That is, calculate the centroids of the two projections, one onto the x-y plane, and the other onto the x-z plane. The centroids of the projections will be projections of the actual centroid, so the answer will be the x, y, and z values you find from these two calculations.

Stated more explicitly: If your points are (x1, y1, z1), (x2, y2, z2),... , to get the x-y centroid, (Cx, Cy), do a calculation using (x1, y1), (x2, y2),... and to get the x-z centroid, (Cx, Cz) use the points (x1, z1), (x2, z2),.... -- just do the second calculation with your same 2D formula, treating the z values as the y in the equation. Then your 3D centroid will be (Cx, Cy, Cz). This will work as long as your surface is flat and isn't parallel to the x-y, x-z, or y-z planes (but if it is parallel it's just the 2D equation).

tom10
@tom10, can be more explicit about this?
Ngu Soon Hui
OK, added a paragraph giving a more explicit description. Does is say what you need to know?
tom10
@tom10, in that case there are two sets of `Cx`. Which one to choose? Or we just pick the average?
Ngu Soon Hui
Both calculations of Cx should give the same result.
tom10