मेरे पास एक बंद उत्तल पॉलीहेड्रॉन है जिसे उत्तल बहुभुज (चेहरे) की एक सरणी द्वारा परिभाषित किया गया है जिसे 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% यकीन नहीं है कि यह सही है क्योंकि मैं ऑनलाइन एक सही एल्गोरिदम नहीं ढूंढ पा रहा हूं। अगर कोई मेरी एल्गोरिदम की पुष्टि कर सकता है या मुझे सही से संदर्भित कर सकता है तो मैं इसकी सराहना करता हूं।
धन्यवाद।
[संपादित करें]
तो यहाँ वास्तविक जावा कोड मैं केन्द्रक को खोजने के लिए उपयोग कर रहा हूँ है। यह पॉलीहेड्रॉन को पॉलीहेड्रोन के अंदर एक मनमानी बिंदु पर परिवर्तित पिरामिड में तोड़ देता है। पिरामिड सेंट्रॉइड के लिए भारित औसत निम्नलिखित सूत्र पर आधारित है।
सी सब = SUM सब पिरामिड (सी पिरामिड * मात्रा पिरामिड)/मात्रा सब
यहाँ (भारी कोड टिप्पणी की) है:
// 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);
कृपया मुझे कोई प्रश्न पूछने में संकोच न करें जो आपके पास हो सकता है इसे बाहर निकालें या आप जो भी त्रुटियां देखते हैं उन्हें इंगित करें।
पोस्ट किया है मैं इसे समर्थन नहीं कर सकता लेकिन http://www.cs.berkeley.edu/~jfc/mirtich/massProps.html एक नज़र लायक हो सकता है। – dmuir
[इस उत्तर] के "[संपादित करें]' "के बाद थोड़ा सा (http://stackoverflow.com/a/4824248/71059) एक समान प्रश्न पर अच्छा दिखता है। – AakashM
अपने कोड में, आपने एक सेंट्रॉइड शुरू किया है लेकिन इसे लूप के अंदर कभी भी इस्तेमाल नहीं किया है। आपके सूत्र के अनुसार, आप इसे अंत में सभी खंडों के योग से विभाजित करते हैं। सेंट्रॉइड को सभी avgToCentroid (centroid.add (avgToCentroid) को जोड़ना नहीं चाहिए? वॉल्यूम के समान सभी पिरामिड वॉल्यूम्स का योग है? –