虚拟机代码:
理论:
前面的(n, i)代表的是组合
组合:
C(n,m)=P(n,m)/P(m,m) =n!/m!(n-m)!
算法流程:
递归构造Bezier曲线
recursive_bezier()
cv::Point2f recursive_bezier(const std::vector<cv::Point2f> &control_points, float t)
{
// TODO: Implement de Casteljau's algorithm
if(control_points.size()==1) return control_points[0];
std::vector<cv::Point2f> points;
for(int i=0;i<control_points.size()-1;i++){
points.push_back(control_points[i] + t*(control_points[i+1] - control_points[i]));
}
return recursive_bezier(points, t);
}
画出Bezier 曲线
void bezier(const std::vector<cv::Point2f> &control_points, cv::Mat &window)
{
// TODO: Iterate through all t = 0 to t = 1 with small steps, and call de Casteljau's
// recursive Bezier algorithm.
for(float t = 0.0;t<=1.0;t=t+0.001){
cv::Point2f p = recursive_bezier(control_points, t);
window.at<cv::Vec3b>(p.y,p.x)[1] = 255;
}
}