Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1.  
  2. // Function to get all bPoints from the given Control Points. The last entry in
  3. // in the Vector is the Point on the Curve given by the actual u Parameter
  4. // e.g. bPoints = {C^0_0, C^0_1, C^0_2, C^0_3, C^0_4, C^1_(r-n+1),.., C^n_r}
  5. vector<Point2D> getBPoints(float u) {
  6.     vector<Point2D> Result;
  7.  
  8.     vector<Point2D> RefPoints=cPoints;
  9.     vector<Point2D> NewPoints;
  10.     while(RefPoints.size()>=2)
  11.     {
  12.         for(int i=0; i<RefPoints.size()-1; ++i)
  13.         {
  14.             NewPoints.push_back(RefPoints[i]*(1-u)+RefPoints[i+1]*u);
  15.             Result.push_back(RefPoints[i]*(1-u)+RefPoints[i+1]*u);
  16.         }
  17.         RefPoints=NewPoints;
  18.         NewPoints.clear();
  19.     }
  20.  
  21. return Result;
  22. }
  23.  
  24. // plots the Bezier Curve using the plot Function, which plots a line.
  25. // Parameter smooth defines how many lines are used to plot the Curve. The more
  26. // lines are used, the more the Curve looks like a real Curve
  27. void plotBCurve(float smooth) {
  28.  
  29.     if(cPoints.size()>2)
  30.     {
  31.         vector<Point2D> Points;
  32.  
  33.         for(int i=0; i<1/smooth; ++i)
  34.         {
  35.             vector<Point2D> Bla=getBPoints(smooth*i);
  36.             Points.push_back(Bla.back());
  37.         }
  38.  
  39.         //render the points:
  40.         for(int i=0; i<Points.size()-1; ++i)
  41.         {
  42.             plotLine(Points[i], Points[i+1], 0, 1);
  43.         }
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement