games101 作业4

作业分析

这次作业比较简单,不会写的话可以参考代码里面的naive_bezier。做的过程中有一个问题就是如何显示绿色线条。需要把naive_bezier里面的:window.at<cv::Vec3b>(point.y, point.x)[2] = 255;改为window.at<cv::Vec3b>(point.y, point.x)[1] = 255;(也不知道大佬是怎么知道的这点。。我确实是只有参考了别人的才知道怎么写)。
其他倒没什么,直接硬解出答案。

代码

cv::Point2f recursive_bezier(const vector<cv::Point2f>& control_points, float t)
{
    // TODO: Implement de Casteljau's algorithm
    auto& p0 = control_points[0];
    auto& p1 = control_points[1];
    auto& p2 = control_points[2];
    auto& p3 = control_points[3];
    auto pp0 = t * p0 + (1 - t) * p1;
    auto pp1 = t * p1 + (1 - t) * p2;
    auto pp2 = t * p2 + (1 - t) * p3;
    auto ppp0 = t * pp0 + (1 - t) * pp1;
    auto ppp1 = t * pp1 + (1 - t) * pp2;
    auto ans = t * ppp0 + (1 - t) * ppp1;
    return cv::Point2f(ans);

}

void bezier(const 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;t<1;t+=0.001)
    {
        auto point=recursive_bezier(control_points, t);
        window.at<cv::Vec3b>(point.y, point.x)[1] = 255;
    }

}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值