Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. float SolveBezierCurve(float x1, float y1, float x2, float y2, float t)
  2. {
  3.     float a = GMin(0.0f, GMin(y1, GMin(y2, 1.0f)));
  4.     float b = GMax(0.0f, GMax(y1, GMax(y2, 1.0f)));
  5.  
  6.     // Starts the looping.
  7.     const int maxIterations = 1000;
  8.     int iterations = 0;
  9.     while (iterations <= maxIterations)
  10.     {
  11.         float c = (a + b) / 2.0f;
  12.         if (abs(BezierFunctionCall(x1, x2, c, t) - 0.0f) < FLT_EPSILON || (b - a) / 2.0f < 0.001f) return c;
  13.  
  14.         iterations++;
  15.  
  16.         if (sign(BezierFunctionCall(x1, x2, c, t)) == sign(BezierFunctionCall(x1, x2, a, t))) a = c;
  17.         else b = c;
  18.     }
  19.  
  20.     return 0.0f;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement