Sorfware for Lexy ( Hexapode )
Dependencies: mbed BLE_API X_NUCLEO_IDB0XA1 MODSERIAL
LIB/Bezier.cpp@5:58acbceb4f9e, 2016-08-20 (annotated)
- Committer:
- Essenceia
- Date:
- Sat Aug 20 19:21:54 2016 +0000
- Revision:
- 5:58acbceb4f9e
- Parent:
- 1:8bab9152933e
Now needs to be debugger;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Essenceia | 1:8bab9152933e | 1 | #include "Bezier.h" |
Essenceia | 1:8bab9152933e | 2 | |
Essenceia | 1:8bab9152933e | 3 | Bezier::Bezier() |
Essenceia | 1:8bab9152933e | 4 | {;} |
Essenceia | 1:8bab9152933e | 5 | Bezier::~Bezier() |
Essenceia | 1:8bab9152933e | 6 | { |
Essenceia | 1:8bab9152933e | 7 | ; |
Essenceia | 1:8bab9152933e | 8 | } |
Essenceia | 1:8bab9152933e | 9 | void Bezier::add_point(float x,float y) |
Essenceia | 1:8bab9152933e | 10 | { |
Essenceia | 1:8bab9152933e | 11 | xpos.push_back(x); |
Essenceia | 1:8bab9152933e | 12 | ypos.push_back(y); |
Essenceia | 1:8bab9152933e | 13 | } |
Essenceia | 1:8bab9152933e | 14 | |
Essenceia | 1:8bab9152933e | 15 | void Bezier::get_pos(float t, float *xret, float *yret) |
Essenceia | 1:8bab9152933e | 16 | { |
Essenceia | 1:8bab9152933e | 17 | int ii, ij, npoints; |
Essenceia | 1:8bab9152933e | 18 | float *x, *y; |
Essenceia | 1:8bab9152933e | 19 | |
Essenceia | 1:8bab9152933e | 20 | npoints = xpos.size(); |
Essenceia | 1:8bab9152933e | 21 | x = new float [npoints]; |
Essenceia | 1:8bab9152933e | 22 | y = new float [npoints]; |
Essenceia | 1:8bab9152933e | 23 | // load with current points |
Essenceia | 1:8bab9152933e | 24 | for (ii=0; ii<npoints; ii++) |
Essenceia | 1:8bab9152933e | 25 | { |
Essenceia | 1:8bab9152933e | 26 | x[ii] = xpos[ii]; |
Essenceia | 1:8bab9152933e | 27 | y[ii] = ypos[ii]; |
Essenceia | 1:8bab9152933e | 28 | } |
Essenceia | 1:8bab9152933e | 29 | |
Essenceia | 1:8bab9152933e | 30 | // iterate over levels |
Essenceia | 1:8bab9152933e | 31 | for (ii=0; ii<npoints-1; ii++) |
Essenceia | 1:8bab9152933e | 32 | { |
Essenceia | 1:8bab9152933e | 33 | for (ij=0; ij<npoints-ii-1; ij++) |
Essenceia | 1:8bab9152933e | 34 | { |
Essenceia | 1:8bab9152933e | 35 | x[ij] = (1.0-t)*x[ij] + t*x[ij+1]; |
Essenceia | 1:8bab9152933e | 36 | y[ij] = (1.0-t)*y[ij] + t*y[ij+1]; |
Essenceia | 1:8bab9152933e | 37 | } |
Essenceia | 1:8bab9152933e | 38 | } |
Essenceia | 1:8bab9152933e | 39 | |
Essenceia | 1:8bab9152933e | 40 | *xret = x[0]; |
Essenceia | 1:8bab9152933e | 41 | *yret = y[0]; |
Essenceia | 1:8bab9152933e | 42 | |
Essenceia | 1:8bab9152933e | 43 | delete [] x; |
Essenceia | 1:8bab9152933e | 44 | delete [] y; |
Essenceia | 1:8bab9152933e | 45 | } |