| 1 | #include "bezier.h" |
|---|---|
| 2 | |
| 3 | CCubicBezier CCubicBezier::With(float Start, float StartDerivative, float EndDerivative, float End) |
| 4 | { |
| 5 | return CCubicBezier(Start, Start + StartDerivative / 3, End - EndDerivative / 3, End); |
| 6 | } |
| 7 | |
| 8 | // f(t) = (1-t)³ a + 3(1-t)²t b + 3(1-t)t² c + t³ d |
| 9 | float CCubicBezier::Evaluate(float t) const |
| 10 | { |
| 11 | return (1 - t) * (1 - t) * (1 - t) * a + 3 * (1 - t) * (1 - t) * t * b + 3 * (1 - t) * t * t * c + t * t * t * d; |
| 12 | } |
| 13 | |
| 14 | // f(t) = 3(1-t)²(b-a) + 6(1-t)t(c-b) + 3t²(d-c) |
| 15 | float CCubicBezier::Derivative(float t) const |
| 16 | { |
| 17 | return 3 * (1 - t) * (1 - t) * (b - a) + 6 * (1 - t) * t * (c - b) + 3 * t * t * (d - c); |
| 18 | } |
| 19 |