Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Function to get all bPoints from the given Control Points. The last entry in
- // in the Vector is the Point on the Curve given by the actual u Parameter
- // 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}
- vector<Point2D> getBPoints(float u) {
- vector<Point2D> Result;
- vector<Point2D> RefPoints=cPoints;
- vector<Point2D> NewPoints;
- while(RefPoints.size()>=2)
- {
- for(int i=0; i<RefPoints.size()-1; ++i)
- {
- NewPoints.push_back(RefPoints[i]*(1-u)+RefPoints[i+1]*u);
- Result.push_back(RefPoints[i]*(1-u)+RefPoints[i+1]*u);
- }
- RefPoints=NewPoints;
- NewPoints.clear();
- }
- return Result;
- }
- // plots the Bezier Curve using the plot Function, which plots a line.
- // Parameter smooth defines how many lines are used to plot the Curve. The more
- // lines are used, the more the Curve looks like a real Curve
- void plotBCurve(float smooth) {
- if(cPoints.size()>2)
- {
- vector<Point2D> Points;
- for(int i=0; i<1/smooth; ++i)
- {
- vector<Point2D> Bla=getBPoints(smooth*i);
- Points.push_back(Bla.back());
- }
- //render the points:
- for(int i=0; i<Points.size()-1; ++i)
- {
- plotLine(Points[i], Points[i+1], 0, 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement