# Bernstein Polynomial Approximation (solved)

This topic is 4373 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.
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);
}
}
}


[Edited by - Ultraseamus on October 4, 2006 8:28:10 AM]

##### Share on other sites
Did you check the output of your binomial coefficient and power functions?

##### Share on other sites
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.

##### Share on other sites
You're welcome! Glad I could help.

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 32
• ### Forum Statistics

• Total Topics
632631
• Total Posts
3007531
• ### Who's Online (See full list)

There are no registered users currently online

×