I realized that I haven't released any snippets in a while so I figured while I was working on some interesting projects of my own that I would release one that I recently decided to write because I don't see the algorithm out there in C# very often. This snippet is useful for plotting preset paths in game development and can be used in many different styles. A race track, an enemy path in a 2D shooter, a plane's flight path, graph editing, so on and so forth. The implementation is simple as well. If you don't want to use the BezierPoint class that is provided then just replace it with the Point class from .NET framework when working with forms applications, or Vector2 from XNA Framework. I use my own class because I thought it would be fun. Anyways, hope you all enjoy and hope it helps some one out there.

Formula for a cubic Bezier curve:

```
^ = Exponent
_ = Subset
[x, y] = (1 - t)^3P_0 + 3(1 - t)^2tP_1 + 3(1 - t)t^2P_2 + t^3P_3
Algorithm Variables:
A = 3 * (P_1 - P_0)
B = 3 * (P_2 - P_1)
C = P_3 - P_0 - A - B
Algorithm (Current Point):
(C * t^3) + (B * t^2) + (A * t) + P_0
```

Have a great year,

Jamie

```
// 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);
```