By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,495 Members | 1,321 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,495 IT Pros & Developers. It's quick & easy.

Bezier curve

P: n/a
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
Nov 11 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

"Peter Morris" <su*****@NOdroopySPAMeyes.comwrote in message
news:uK**************@TK2MSFTNGP03.phx.gbl...
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

Nov 11 '07 #2

P: n/a
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
Nov 11 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.