Advertisement
Guest User

bezier

a guest
May 10th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.89 KB | None | 0 0
  1.  
  2.   // get the x:y position at this ratio (t)
  3.   Point _positionAtBezierRatio(num t, EditableBezierPoint p1, EditableBezierPoint p2) {
  4.     return new Point(_xAtBezierRatio(t, p1, p2), _yAtBezierRatio(t, p1, p2));
  5.   }
  6.   num _xAtBezierRatio(num t, EditableBezierPoint p1, EditableBezierPoint p2) {
  7.     num sX = p1.x;
  8.     num cX1 = p1.cx2;
  9.     num eX = p2.x;
  10.     num cX2 =p2.cx1;
  11.  
  12.     num xTmp = (pow(1 - t, 3) * sX) +
  13.         (3 * pow(1 - t, 2) * t * cX1) +
  14.         (3 * (1 - t) * pow(t, 2) * cX2) +
  15.         (pow(t, 3) * eX);
  16.  
  17.     return xTmp;
  18.   }
  19.  
  20.   num _yAtBezierRatio(num t, EditableBezierPoint p1, EditableBezierPoint p2) {
  21.     num sY = p1.y;
  22.     num cY1 = p1.cy2;
  23.     num eY = p2.y;
  24.     num cY2 =p2.cy1;
  25.  
  26.     num yTmp = (pow(1 - t, 3) * sY) +
  27.         (3 * pow(1 - t, 2) * t * cY1) +
  28.         (3 * (1 - t) * pow(t, 2) * cY2) +
  29.         (pow(t, 3) * eY);
  30.  
  31.     return yTmp;
  32.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement