public static BinomialCoefficient ( int n, int k ) : long | ||
n | int | The n. |
k | int | The k. |
리턴 | long |
/// <summary> /// Calculates the point on the given bezier curve with the specified t parameter. /// </summary> /// <param name="points">The points.</param> /// <param name="t">The t parameter, a value between 0.0f and 1.0f.</param> /// <param name="parallel">The parallel value.</param> /// <returns>Resulting point.</returns> /// <remarks>The <paramref name="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.</remarks> public static Vector2 CalculatePoint(IList <Vector2> points, float t, float parallel) { Vector2 r = new Vector2(); double c = 1.0d - (double)t; float temp; int i = 0; foreach (Vector2 pt in points) { temp = (float)MathHelper.BinomialCoefficient(points.Count - 1, i) * (float)(System.Math.Pow(t, i) * System.Math.Pow(c, (points.Count - 1) - i)); r.X += temp * pt.X; r.Y += temp * pt.Y; i++; } if (parallel == 0.0f) { return(r); } Vector2 perpendicular = new Vector2(); if (t != 0.0f) { perpendicular = r - BezierCurve.CalculatePointOfDerivative(points, t); } else { perpendicular = points[1] - points[0]; } return(r + Vector2.Normalize(perpendicular).PerpendicularRight *parallel); }
private static Vector2 CalculatePointOfDerivative(IList <Vector2> points, float t) { Vector2 vector2_1 = new Vector2(); double x = 1.0 - (double)t; int k = 0; foreach (Vector2 vector2_2 in (IEnumerable <Vector2>)points) { float num = (float)MathHelper.BinomialCoefficient(points.Count - 2, k) * (float)(Math.Pow((double)t, (double)k) * Math.Pow(x, (double)(points.Count - 2 - k))); vector2_1.X += num * vector2_2.X; vector2_1.Y += num * vector2_2.Y; ++k; } return(vector2_1); }
/// <summary> /// Calculates the point with the specified t of the derivative of the given bezier function. /// </summary> /// <param name="points">The points.</param> /// <param name="t">The t parameter, value between 0.0f and 1.0f.</param> /// <returns>Resulting point.</returns> private static Vector2 CalculatePointOfDerivative(IList <Vector2> points, float t) { Vector2 r = new Vector2(); double c = 1.0d - (double)t; float temp; int i = 0; foreach (Vector2 pt in points) { temp = (float)MathHelper.BinomialCoefficient(points.Count - 2, i) * (float)(System.Math.Pow(t, i) * System.Math.Pow(c, (points.Count - 2) - i)); r.X += temp * pt.X; r.Y += temp * pt.Y; i++; } return(r); }
public static Vector2 CalculatePoint(IList <Vector2> points, float t, float parallel) { Vector2 vector2_1 = new Vector2(); double x = 1.0 - (double)t; int k = 0; foreach (Vector2 vector2_2 in (IEnumerable <Vector2>)points) { float num = (float)MathHelper.BinomialCoefficient(points.Count - 1, k) * (float)(Math.Pow((double)t, (double)k) * Math.Pow(x, (double)(points.Count - 1 - k))); vector2_1.X += num * vector2_2.X; vector2_1.Y += num * vector2_2.Y; ++k; } if ((double)parallel == 0.0) { return(vector2_1); } Vector2 vector2_3 = new Vector2(); Vector2 vec = (double)t == 0.0 ? points[1] - points[0] : vector2_1 - BezierCurve.CalculatePointOfDerivative(points, t); return(vector2_1 + Vector2.Normalize(vec).PerpendicularRight *parallel); }