Jump to content
  • Advertisement
Sign in to follow this  
Ultraseamus

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!