私は、3次元空間の頂点の配列によって定義される凸多面体(面)の配列によって定義される閉じた凸多面体を持っています。均一な密度を仮定して、多面体の重心を見つけようとしています。現時点で私はこの擬似コードのアルゴリズムで計算します。凸多面体の重心
public Vector3 getCentroid() {
Vector3 centroid = (0, 0, 0);
for (face in faces) {
Vector3 point = face.centroid;
point.multiply(face.area());
centroid.add(point);
}
centroid.divide(faces.size());
return centroid;
}
これは基本的に、顔の重心の加重平均をとります。私は正しいアルゴリズムをオンラインで見つけることができなかったので、これが正しいことを100%確信しているわけではありません。誰かが私のアルゴリズムを確認したり、正しいものを私に紹介したりすることができたら、私はそれを感謝します。
ありがとうございました。
[EDIT]だからここ
は、私は、重心を見つけるために使用しています実際のJavaコードです。多面体を多面体内の任意の点に収束するピラミッドに分割する。ピラミッド重心の加重平均は、次の式に基づいています。
C 全て = SUM 全てピラミッド(C ピラミッド *ボリュームピラミッド)/体積ここ全て
は(重くコードコメント)である:
// Compute the average of the facial centroids.
// This gives an arbitrary point inside the polyhedron.
Vector3 avgPoint = new Vector3(0, 0, 0);
for (int i = 0; i < faces.size(); i++) {
avgPoint.add(faces.get(i).centroid);
}
avgPoint.divide(faces.size());
// Initialise the centroid and the volume.
centroid = new Vector3(0, 0, 0);
volume = 0;
// Loop through each face.
for (int i = 0; i < faces.size(); i++) {
Face face = faces.get(i);
// Find a vector from avgPoint to the centroid of the face.
Vector3 avgToCentroid = face.centroid.clone();
avgToCentroid.sub(avgPoint);
// Gives the unsigned minimum distance between the face and a parallel plane on avgPoint.
float distance = avgToCentroid.scalarProjection(face.getNormal());
// Finds the volume of the pyramid using V = 1/3 * B * h
// where: B = area of the pyramid base.
// h = pyramid height.
float pyramidVolume = face.getArea() * distance/3;
// Centroid of a pyramid is 1/4 of the height up from the base.
// Using 3/4 here because vector is travelling 'down' the pyramid.
avgToCentroid.multiply(0.75f);
avgToCentroid.add(avgPoint);
// avgToCentroid is now the centroid of the pyramid.
// Weight it by the volume of the pyramid.
avgToCentroid.multiply(pyramidVolume);
volume += pyramidVolume;
}
// Average the weighted sum of pyramid centroids.
centroid.divide(volume);
を
お気軽にお問い合わせくださいあなたが見ているエラーを指摘してください。
matlab codeを掲載しました。 – dmuir
[この回答](http://stackoverflow.com/a/4824248/71059)の "[編集]" "の後のビットも同様の質問になります。 – AakashM
あなたのコードでは、重心を初期化しましたが、ループ内でそれを使用したことはありません。あなたの数式によると、最後にすべてのボリュームの合計で除算します。すべてのavgToCentroid(centroid.add(avgToCentroid))の重心を集計すべきではありませんか?ボリュームと同じピラミッドボリュームの合計ですか? –