Bezier Curves in WPF, C# and Math

Written a pretty simple (but cool) WPF/.NET app to experiment with the parametric cubic curves also known as Bernstein basis polynomials.

Bezier curves are implemented in many vector graphics applications.


Obviously WPF itself has Bezier path geometry built in, so normally you would never need to do this manually

Needs .NET framework 3.5 to run.

 
public IEnumerable GetBezierPoints( 
	Vector A, Vector B, 
	Vector C, Vector D ) {

	List vectors = new List();
	
	for( double t = 0.0d; 
		t<=1.0; 
		t+=1.0/_beizerPoints.Count ) {

		double tbs = Math.Pow(t, 2);
		double tbc = Math.Pow(t, 3);
		double tas = Math.Pow((1-t), 2);
		double tac = Math.Pow((1-t), 3);

		vectors.Add( new Vector{
						X=	+ tac * A.X
							+ 3 * t * tas * B.X
							+ 3 * tbs * (1-t) * C.X
							+ tbc * D.X,
						Y=	+ tac * A.Y
							+ 3 * t * tas * B.Y
							+ 3 * tbs * (1-t) * C.Y
							+ tbc * D.Y
							} );
	}
	
	return vectors;
}
developer-x.com
developer-x.com

Copyright Tim Scarfe (c) 1999-2010