
// Class to hold the X and Y variable for each point. public class BezierPoint { public float X { get; private set; } public float Y { get; private set; } public BezierPoint(float x, float y) { this.X = x; this.Y = y; } } // Method used to get the current point in the curve based on t. public BezierPoint CurrentPoint(float t, BezierPoint p0, BezierPoint p1, BezierPoint p2, BezierPoint p3) { float cube = t * t * t; float square = t * t; BezierPoint a = 3 * (p1 - p0); BezierPoint b = 3 * (p2 - p0); BezierPoint c = p3 - p0 - a - b; BezierPoint r = (c * cube) + (b * square) + (a * t) + p0; return r; } // Implementation (used with timer in most cases): BezierCurve ObjectPoint; BezierCurve EndPoint1 = new BezierCurve(200, 80); BezierCurve ControlPoint1 = new BezierCurve(180, 160); BezierCurve ControlPoint2 = new BezierCurve(90, 300); BezierCurve EndPoint2 = new BezierCurve(312, 115); for (float t = 0.0f; t < 1.0f; t += 0.01f) ObjectPoint = CurrentPoint(t, EndPoint1, ControlPoint1, ControlPoint2, EndPoint2);