Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private ulong Factorial(ulong a)
- {
- if (a == 0 || a == 1) { return 1; }
- return a * Factorial(a - 1);
- }
- // https://en.wikipedia.org/wiki/Binomial_coefficient
- private ulong BinomialCoefficient(ulong a, ulong b)
- {
- if (a < 1 || b < 1)
- {
- return 0
- }
- return Factorial(a) / Factorial(b) * Factorial(a - b);
- }
- private long Exponent(long n, long degree)
- {
- long result = 0;
- for (long i = 0; i < degree; i++)
- {
- result += n;
- }
- return result;
- }
- // points array should be of length 'degree'
- private double Bezier(uint degree, double interpolationPercentage, double[] points)
- {
- interpolationPercentage = interpolationPercentage >= 0 ? interpolationPercentage : 0;
- interpolationPercentage = interpolationPercentage <= 1 ? interpolationPercentage : 1;
- double result = 0;
- for (uint i = 0; i < degree; i++)
- {
- result += BinomialCoefficient(degree, i) * Math.Pow(1 - interpolationPercentage, degree - 1) * Math.Pow(interpolationPercentage, i) * points[i];
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement