Bezier Points
-
I am using DrawBezier to display a user defined bezier curve. I need the x,y values along the curve (not just points used to create the curve but each point along the curve). I have the mathematical formula but if the graphics is generating the points to paint is there a way to access the x,y locations of points it is painting? Thanks
-
I am using DrawBezier to display a user defined bezier curve. I need the x,y values along the curve (not just points used to create the curve but each point along the curve). I have the mathematical formula but if the graphics is generating the points to paint is there a way to access the x,y locations of points it is painting? Thanks
Why don't you make your own method for that. May be the following code might help. If my memory serves me correctly, I've copied this code from a book by Charles Petzold on Windows forms programming.
public void DrawBezier(Graphics grfx, Pen pen, Point p0, Point p1, Point p2, Point p3) { Point[] curve = new Point[100]; for (int i = 0; i < curve.Length; i++) { float u = (float) i / (curve.Length - 1); //Console.WriteLine(u); float y=((1-u)*(1-u)*(1-u)* p0.Y) + (3*u* (1-u)*(1-u)* p1.Y) + (3*u*u* (1-u)* p2.Y) + (u*u*u* p3.Y); float x=((1-u)*(1-u)*(1-u)* p0.X) + (3*u* (1-u)*(1-u)* p1.X) + (3*u*u* (1-u)* p2.X) + (u*u*u * p3.X); curve[i] = new Point((int) Math.Round(x), (int) Math.Round(y)); } grfx.DrawLines(pen, curve); }