void drawBB()
{
if(pointList.size() > 0)
{
drawList.clear();
int d = pointList.size() - 1;
for(float t = .1; t < 1; t += .1)
{
float posX = 0;
float posY = 0;
for(int i = 0; i <= d; ++i)
{
int fact = BB(d,i);
float part2 = power(1 - t,d-i);
float part3 = power(t,i);
int partx = pointList.mX;
int party = pointList.mY;
posX += fact * part2 * part3 * partx;
posY += fact * part2 * part3 * party;
}
CS200::Point2D Point1((posX),(posY));
drawList.push_back(Point1);
}
}
}
Bernstein Polynomial Approximation (solved)
trying to code Bernstein Polynomial Approximation to draw a curve between a set number of points, but i think my understanding of the material is just a bit too weak, this is my code right now. I am coding in C++, the function BB returns the binomial coefficient, pointList is just the list on control points, power will raise a number to the specified power, and drawList is the list of points to be drawn.
When there are 2 points it will draw a straight line of points as it should, with a third point it forms a curve but it is a bit exagerated and in the wrong position, and after that it gets worse until there is no visable curve. This seems like a very simple problem, and i am surprised i have not solved it yet, but my brain must have given out on me. Any help would be great.
[Edited by - Ultraseamus on October 4, 2006 8:28:10 AM]
wow..., i ran tests on my functions, but i missed something in my power function, when the base is a float (and the exponent is not 0 or 1) it looks like i accidently forced it to an int, throwing off all of my data. It must be time for me too go to bed, because i was stuck on that for over an hour :/. Thank You for your help. It is atleast nice to know i had the math right.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement