I have a problem of writing the beizer function. I have written a simple code in c# :
public static PointF[] BeizerFunction (int interval, PointF point0, PointF point1, PointF point2) {
//x = (1 - t) * (1 - t) * p[0].x + 2 * (1 - t) * t * p[1].x + t * t * p[2].x;
//y = (1 - t) * (1 - t) * p[0].y + 2 * (1 - t) * t * p[1].y + t * t * p[2].y;
var Points = new PointF[interval];
var time = 1.0f / (float) interval;
for (var i=0; i<Points.Length; i++) {
var point = Points [i];
point = new PointF ();
point.X = (1 - time) * (1 - time) * point0.X
+ 2 * (1 - time) * time * point1.X
+ time * time * point2.X;
point.Y = (1 - time) * (1 - time) * point0.Y
+ 2 * (1 - time) * time * point1.Y
+ time * time * point2.Y;
Points [i] = point;
time ++;
}
return Points;
}
By application is listen to mouse move so I would guess the mouse pointer would be the control points for this function. The above code if correct should give me a beizer curve from three points.
In reality, there multiple curves so there would be more than 3 points. To join the beize curve together I do something like this.
Bezier(p0.5, p1, p1.5);
Bezier(p1.5, p2, p2.5);
Bezier(p2.5, p3, p3.5);
The c# code to draw just a 3 points is this
var p0 = new PointF (50, 50);
var p1 = new PointF (100, 100);
var p2 = new PointF (150, 50);
var points = QuadraticBezierFunction.BeizerFunction (100, p0, p1, p2);
for (var i=0; points != null && i<points.Length-1; i=i+1)
canvas.DrawLine (points[i].X, points[i].Y, points[i+1].X, points[i+1].Y, new Android.Graphics.Paint ());
When I try to draw the curve it doesn't look a curve.