Commit e201b5f2 by Pierre Fernbach

### implement curve splitting with deCasteljau's algorithm

parent 941872a5
 ... ... @@ -298,6 +298,41 @@ struct bezier_curve : public curve_abc } /** * @brief split split the curve in 2 at time t * @param t * @return */ std::pair split(const Numeric T){ t_point_t wps_first(size_),wps_second(size_); const double t = T/T_; wps_first[0] = pts_.front(); wps_second[degree_] = pts_.back(); t_point_t casteljau_pts = waypoints(); size_t id = 1; while(casteljau_pts.size() > 1){ casteljau_pts = deCasteljauReduction(casteljau_pts,t); wps_first[id] = casteljau_pts.front(); wps_second[degree_-id] = casteljau_pts.back(); ++id; } bezier_curve_t c_first(wps_first.begin(), wps_first.end(), T,mult_T_); bezier_curve_t c_second(wps_second.begin(), wps_second.end(), T_-T,mult_T_); return std::make_pair(c_first,c_second); } bezier_curve_t extract(const Numeric t1, const Numeric t2){ if(t1 < 0. || t1 > T_ || t2 < 0. || t2 > T_) throw std::out_of_range("In Extract curve : times out of bounds"); if(t1 == 0.) return split(t2).first; if(t2 == T_) return split(t1).second; std::pair c_split = this->split(t1); return c_split.second->split(t2).first; } private: template ... ...
 ... ... @@ -843,6 +843,82 @@ void BezierEvalDeCasteljau(bool& error){ } /** * @brief BezierSplitCurve test the 'split' method of bezier curve * @param error */ void BezierSplitCurve(bool& error){ // test for degree 5 int n = 5; double t_min = 0.2; double t_max = 10; for(size_t i = 0 ; i < 1 ; ++i){ // build a random curve and split it at random time : //std::cout<<"build a random curve"< wps; for(size_t j = 0 ; j <= n ; ++j){ wps.push_back(randomPoint(-10.,10.)); } double t = (rand()/(double)RAND_MAX )*(t_max-t_min) + t_min; double ts = (rand()/(double)RAND_MAX )*(t); bezier_curve_t c(wps.begin(), wps.end(),t); std::pair cs = c.split(ts); //std::cout<<"split curve of duration "< 1e-14){ error = true; std::cout<<"first splitted curve and original curve doesn't correspond, error = "< 1e-14){ error = true; std::cout<<"second splitted curve and original curve doesn't correspond, error = "<
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!