static bool test_bezier_curve(void) { bool ret = true; ret = ret && (coords[0] == bezier_curve(0., 4, coords)); ret = ret && (coords[4] == bezier_curve(1., 4, coords)); return ret; }
static bool test_bezier_increase_degree(void) { double coords2[6]; bezier_increase_degree(4, coords2, coords); double err = 0.; for (double x = 0.; x < 1.; x += 0.01) { double a = bezier_curve(x, 4, coords); double b = bezier_curve(x, 5, coords2); err += pow(a - b, 2); } return (err < 1.E-28); }
static bool test_bezier_split(void) { double coords[5] = { 0., 1., 0.5, 1., 0.5 }; double coordsA[5]; double coordsB[5]; bezier_split(0.5, 4, coordsA, coordsB, coords); double err = 0.; for (double x = 0.; x < 1.; x += 0.01) { double a = bezier_curve(x, 4, coords); double b = (x <= 0.5) ? bezier_curve(2. * x, 4, coordsA) : bezier_curve(2. * (x - 0.5), 4, coordsB); err += pow(a - b, 2); } return (err < 1.E-28); }
void curve::draw(){ drawControlPoints(); if(size > 1){ CurveX.resize(0); CurveY.resize(0); CurveZ.resize(0); bezier_curve(ControlX, ControlY, ControlZ); } for(int i = 0; i < CurveX.size(); i++){ glPushMatrix(); glDisable (GL_LIGHTING); glColor3f(0.0,0.0,1.0); glTranslatef(CurveX[i], CurveY[i], CurveZ[i]); glutSolidSphere(0.05, 20, 20); glEnable(GL_LIGHTING); glPopMatrix(); } }
vector<float> curve::getCurvePointsZ(){ if(CurveX.size() == 0 && size > 1){ bezier_curve(ControlX, ControlY, ControlZ); } return CurveZ; }