Bezier curve

  • Thread starter Thread starter Peter Morris
  • Start date Start date
P

Peter Morris

Hi all

I want to draw a line as if it were being drawn in real-time by a person.
To save lots of data I think that storing 4 points in memory and drawing a
bezier curve would be efficient. What I need to know is, how can I
determine each of the required pixel positions so that I may loop through
them and draw them onto a canvas over a timespan of (for example) 1 second?


Thankyou!


Pete
 
http://www.moshplant.com/direct-or/bezier/ will give you the math, given the
four points. To draw the curve in real time, start at the point with the
smallest x coordinate, and calculate y for each pixel, as you increment the
x coordinate by one. Stop when you reach the point with the largest x
coordinate.

A Google search on "Bezier curve" will give you many useful links.
 
That site had just what I needed, thanks :-)

private Point GetBezierPoint(float t, Point p0, Point p1, Point p2, Point
p3)

{

float cx = 3 * (p1.X - p0.X);

float bx = 3 * (p2.X - p1.X) - cx;

float ax = p3.X - p0.X - cx - bx;

float cy = 3 * (p1.Y - p0.Y);

float by = 3 * (p2.Y - p1.Y) - cy;

float ay = p3.Y - p0.Y - cy - by;

float tCubed = t * t * t;

float tSquared = t * t;

float resultX = (ax * tCubed) + (bx * tSquared) + (cx * t) + p0.X;

float resultY = (ay * tCubed) + (by * tSquared) + (cy * t) + p0.Y;

return new Point((int)resultX, (int)resultY);

}



Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top