OpenTK.BezierCurve Struct Reference

Represents a bezier curve with as many points as you want. More...

List of all members.

Public Member Functions

 BezierCurve (IEnumerable< Vector2 > points)
 Constructs a new BezierCurve.
 BezierCurve (params Vector2[] points)
 Constructs a new BezierCurve.
 BezierCurve (float parallel, params Vector2[] points)
 Constructs a new BezierCurve.
 BezierCurve (float parallel, IEnumerable< Vector2 > points)
 Constructs a new BezierCurve.
Vector2 CalculatePoint (float t)
 Calculates the point with the specified t.
float CalculateLength (float precision)
 Calculates the length of this bezier curve.

Static Public Member Functions

static float CalculateLength (IList< Vector2 > points, float precision)
 Calculates the length of the specified bezier curve.
static float CalculateLength (IList< Vector2 > points, float precision, float parallel)
 Calculates the length of the specified bezier curve.
static Vector2 CalculatePoint (IList< Vector2 > points, float t)
 Calculates the point on the given bezier curve with the specified t parameter.
static Vector2 CalculatePoint (IList< Vector2 > points, float t, float parallel)
 Calculates the point on the given bezier curve with the specified t parameter.

Public Attributes

float Parallel
 The parallel value.

Properties

IList< Vector2Points [get]
 Gets the points of this curve.

Detailed Description

Represents a bezier curve with as many points as you want.

Definition at line 21 of file BezierCurve.cs.


Constructor & Destructor Documentation

OpenTK.BezierCurve.BezierCurve ( IEnumerable< Vector2 points  ) 

Constructs a new BezierCurve.

Parameters:
points The points.

Definition at line 60 of file BezierCurve.cs.

00061         {
00062             if (points == null)
00063                 throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
00064 
00065             this.points = new List<Vector2>(points);
00066             this.Parallel = 0.0f;
00067         }

OpenTK.BezierCurve.BezierCurve ( params Vector2[]  points  ) 

Constructs a new BezierCurve.

Parameters:
points The points.

Definition at line 73 of file BezierCurve.cs.

00074         {
00075             if (points == null)
00076                 throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
00077 
00078             this.points = new List<Vector2>(points);
00079             this.Parallel = 0.0f;
00080         }

OpenTK.BezierCurve.BezierCurve ( float  parallel,
params Vector2[]  points 
)

Constructs a new BezierCurve.

Parameters:
parallel The parallel value.
points The points.

Definition at line 87 of file BezierCurve.cs.

00088         {
00089             if (points == null)
00090                 throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
00091 
00092             this.Parallel = parallel;
00093             this.points = new List<Vector2>(points);
00094         }

OpenTK.BezierCurve.BezierCurve ( float  parallel,
IEnumerable< Vector2 points 
)

Constructs a new BezierCurve.

Parameters:
parallel The parallel value.
points The points.

Definition at line 101 of file BezierCurve.cs.

00102         {
00103             if (points == null)
00104                 throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
00105 
00106             this.Parallel = parallel;
00107             this.points = new List<Vector2>(points);
00108         }


Member Function Documentation

static float OpenTK.BezierCurve.CalculateLength ( IList< Vector2 points,
float  precision,
float  parallel 
) [static]

Calculates the length of the specified bezier curve.

Parameters:
points The points.
precision The precision value.
parallel The parallel value.
Returns:
Length of curve.

The precision gets better as the precision value gets smaller.

The parallel parameter defines whether the curve should be calculated as a parallel curve to the original bezier curve. A value of 0.0f represents the original curve, 5.0f represents a curve that has always a distance of 5.0f to the orignal curve.

Definition at line 164 of file BezierCurve.cs.

00165         {
00166             float length = 0.0f;
00167             Vector2 old = BezierCurve.CalculatePoint(points, 0.0f, parallel);
00168 
00169             for (float i = precision; i < (1.0f + precision); i += precision)
00170             {
00171                 Vector2 n = CalculatePoint(points, i, parallel);
00172                 length += (n - old).Length;
00173                 old = n;
00174             }
00175 
00176             return length;
00177         }

static float OpenTK.BezierCurve.CalculateLength ( IList< Vector2 points,
float  precision 
) [static]

Calculates the length of the specified bezier curve.

Parameters:
points The points.
precision The precision value.
Returns:
The precision gets better as the precision value gets smaller.

Definition at line 146 of file BezierCurve.cs.

00147         {
00148             return BezierCurve.CalculateLength(points, precision, 0.0f);
00149         }

float OpenTK.BezierCurve.CalculateLength ( float  precision  ) 

Calculates the length of this bezier curve.

Parameters:
precision The precision.
Returns:
Length of curve.

The precision gets better as the precision value gets smaller.

Definition at line 132 of file BezierCurve.cs.

00133         {
00134             return BezierCurve.CalculateLength(points, precision, Parallel);
00135         }

static Vector2 OpenTK.BezierCurve.CalculatePoint ( IList< Vector2 points,
float  t,
float  parallel 
) [static]

Calculates the point on the given bezier curve with the specified t parameter.

Parameters:
points The points.
t The t parameter, a value between 0.0f and 1.0f.
parallel The parallel value.
Returns:
Resulting point.

The parallel parameter defines whether the curve should be calculated as a parallel curve to the original bezier curve. A value of 0.0f represents the original curve, 5.0f represents a curve that has always a distance of 5.0f to the orignal curve.

Definition at line 201 of file BezierCurve.cs.

00202         {
00203             Vector2 r = new Vector2();
00204             double c = 1.0d - (double)t;
00205             float temp;
00206             int i = 0;
00207 
00208             foreach (Vector2 pt in points)
00209             {
00210                 temp = (float)MathHelper.BinomialCoefficient(points.Count - 1, i) * (float)(System.Math.Pow(t, i) *
00211                         System.Math.Pow(c, (points.Count - 1) - i));
00212 
00213                 r.X += temp * pt.X;
00214                 r.Y += temp * pt.Y;
00215                 i++;
00216             }
00217 
00218             if (parallel == 0.0f)
00219                 return r;
00220 
00221             Vector2 perpendicular = new Vector2();
00222 
00223             if (t != 0.0f)
00224                 perpendicular = r - BezierCurve.CalculatePointOfDerivative(points, t);
00225             else
00226                 perpendicular = points[1] - points[0];
00227 
00228             return r + Vector2.Normalize(perpendicular).PerpendicularRight * parallel;
00229         }

static Vector2 OpenTK.BezierCurve.CalculatePoint ( IList< Vector2 points,
float  t 
) [static]

Calculates the point on the given bezier curve with the specified t parameter.

Parameters:
points The points.
t The t parameter, a value between 0.0f and 1.0f.
Returns:
Resulting point.

Definition at line 185 of file BezierCurve.cs.

00186         {
00187             return BezierCurve.CalculatePoint(points, t, 0.0f);
00188         }

Vector2 OpenTK.BezierCurve.CalculatePoint ( float  t  ) 

Calculates the point with the specified t.

Parameters:
t The t value, between 0.0f and 1.0f.
Returns:
Resulting point.

Definition at line 120 of file BezierCurve.cs.

00121         {
00122             return BezierCurve.CalculatePoint(points, t, Parallel);
00123         }


Member Data Documentation

The parallel value.

This value defines whether the curve should be calculated as a parallel curve to the original bezier curve. A value of 0.0f represents the original curve, 5.0f i.e. stands for a curve that has always a distance of 5.0f to the orignal curve at any point.

Definition at line 34 of file BezierCurve.cs.


Property Documentation

IList<Vector2> OpenTK.BezierCurve.Points [get]

Gets the points of this curve.

The first point and the last points represent the anchor points.

Definition at line 45 of file BezierCurve.cs.

 All Classes Functions Variables Enumerations Properties Events

Generated on Tue Mar 9 14:59:14 2010 for The Open Toolkit library by  doxygen 1.6.1