Julia DESMAZES / Mbed 2 deprecated Hexapode

Dependencies:   mbed BLE_API X_NUCLEO_IDB0XA1 MODSERIAL

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Bezier.cpp Source File

Bezier.cpp

00001 #include "Bezier.h"
00002 
00003 Bezier::Bezier()
00004 {;}
00005 Bezier::~Bezier()
00006 {
00007     ;
00008     }
00009 void Bezier::add_point(float x,float y)
00010 {
00011         xpos.push_back(x);
00012         ypos.push_back(y);
00013     }
00014     
00015 void Bezier::get_pos(float t, float *xret, float *yret)
00016 {
00017         int ii, ij, npoints;
00018         float *x, *y;
00019 
00020         npoints = xpos.size();
00021         x = new float [npoints];
00022         y = new float [npoints];
00023         // load with current points
00024         for (ii=0; ii<npoints; ii++)
00025         {
00026             x[ii] = xpos[ii];
00027             y[ii] = ypos[ii];
00028         }
00029 
00030         // iterate over levels
00031         for (ii=0; ii<npoints-1; ii++)
00032         {
00033             for (ij=0; ij<npoints-ii-1; ij++)
00034             {
00035                 x[ij] = (1.0-t)*x[ij] + t*x[ij+1];
00036                 y[ij] = (1.0-t)*y[ij] + t*y[ij+1];
00037             }
00038         }
00039 
00040         *xret = x[0];
00041         *yret = y[0];
00042 
00043         delete [] x;
00044         delete [] y;
00045     }