पर अंक खोजने के लिए डी बोर्स एल्गोरिदम लागू करना मैं कई हफ्तों तक इस पर काम कर रहा हूं लेकिन मेरे एल्गोरिदम ठीक से काम करने में असमर्थ रहा हूं और मैं अपने wits अंत में हूं। यहाँ मैं क्या हासिल किया है का एक उदाहरण है:बी-स्पलाइन
यदि सब कुछ काम कर रहा था मैं अंत में एक आदर्श सर्कल/अंडाकार उम्मीद करेंगे।
मेरे नमूना बिंदु (सफेद में) हर बार एक नया नियंत्रण बिंदु (पीले रंग में) जोड़ा जाता है, फिर से गणना की जाती है। 4 नियंत्रण बिंदुओं पर सबकुछ सही दिखता है, फिर से जब मैं पहली चीजों के शीर्ष पर 5 वें जोड़ता हूं तो ठीक दिखता है, लेकिन फिर 6 वें स्थान पर यह भी पक्ष से बाहर निकलना शुरू होता है और 7 वें स्थान पर यह उत्पत्ति तक कूद जाता है!
नीचे मैं अपना कोड पोस्ट करूंगा, जहां calculateWeightForPointI
में वास्तविक एल्गोरिदम शामिल है। और संदर्भ के लिए- here is the information i'm trying to follow. अगर कोई मेरी तलाश कर सकता है तो मैं बहुत अच्छा होगा।
void updateCurve(const std::vector<glm::vec3>& controls, std::vector<glm::vec3>& samples)
{
int subCurveOrder = 4; // = k = I want to break my curve into to cubics
// De boor 1st attempt
if(controls.size() >= subCurveOrder)
{
createKnotVector(subCurveOrder, controls.size());
samples.clear();
for(int steps=0; steps<=20; steps++)
{
// use steps to get a 0-1 range value for progression along the curve
// then get that value into the range [k-1, n+1]
// k-1 = subCurveOrder-1
// n+1 = always the number of total control points
float t = (steps/20.0f) * (controls.size() - (subCurveOrder-1)) + subCurveOrder-1;
glm::vec3 newPoint(0,0,0);
for(int i=1; i <= controls.size(); i++)
{
float weightForControl = calculateWeightForPointI(i, subCurveOrder, controls.size(), t);
newPoint += weightForControl * controls.at(i-1);
}
samples.push_back(newPoint);
}
}
}
//i = the weight we're looking for, i should go from 1 to n+1, where n+1 is equal to the total number of control points.
//k = curve order = power/degree +1. eg, to break whole curve into cubics use a curve order of 4
//cps = number of total control points
//t = current step/interp value
float calculateWeightForPointI(int i, int k, int cps, float t)
{
//test if we've reached the bottom of the recursive call
if(k == 1)
{
if(t >= knot(i) && t < knot(i+1))
return 1;
else
return 0;
}
float numeratorA = (t - knot(i));
float denominatorA = (knot(i + k-1) - knot(i));
float numeratorB = (knot(i + k) - t);
float denominatorB = (knot(i + k) - knot(i + 1));
float subweightA = 0;
float subweightB = 0;
if(denominatorA != 0)
subweightA = numeratorA/denominatorA * calculateWeightForPointI(i, k-1, cps, t);
if(denominatorB != 0)
subweightB = numeratorB/denominatorB * calculateWeightForPointI(i+1, k-1, cps, t);
return subweightA + subweightB;
}
//returns the knot value at the passed in index
//if i = 1 and we want Xi then we have to remember to index with i-1
float knot(int indexForKnot)
{
// When getting the index for the knot function i remember to subtract 1 from i because of the difference caused by us counting from i=1 to n+1 and indexing a vector from 0
return knotVector.at(indexForKnot-1);
}
//calculate the whole knot vector
void createKnotVector(int curveOrderK, int numControlPoints)
{
int knotSize = curveOrderK + numControlPoints;
for(int count = 0; count < knotSize; count++)
{
knotVector.push_back(count);
}
}
http://chi3x10.wordpress.com/2009/10/18/de-boor-algorithm-in-c/ आप थोड़ी मदद – Saqlain
बी splines उत्तल पतवार संपत्ति प्रदर्शन प्राप्त कर सकते हैं । यदि आप प्रत्येक क्रमिक नियंत्रण बिंदु से एक रेखा खींचते हैं, तो क्या आप उत्तल बहुभुज के साथ समाप्त होते हैं? ऐसा लगता है कि कुछ किनारों को छेड़छाड़ की जाती है। –
@ ब्रेटहेल मुझे डर है कि मैं काफी अनुवर्ती नहीं हूं? मैं फिलहाल 2 डी में काम कर रहा हूं लेकिन मेरे बी-स्लाइन वक्र (जैसा कि सफेद बिंदुओं द्वारा परिभाषित किया गया है) के किनारों में से कोई भी अंतर नहीं लग रहा है .. ओह रुको हम ओवरलैपिंग नियंत्रण बिंदुओं के बारे में बात कर रहे हैं? यह जानबूझकर है, 5 वें, 6 वें और 7 वें अंक सर्कल बनाने की कोशिश करते समय 1, 2 और 3 ओवरलैप करते हैं। मुझे हल करने में मदद करने के लिए समय निकालने के लिए धन्यवाद, मैं वास्तव में संघर्ष कर रहा हूं। – Holly