当前位置:网站首页>【GAMES101】作业4 Bézier 曲线
【GAMES101】作业4 Bézier 曲线
2022-07-02 15:10:00 【vv就是vv呀】
【GAMES101】作业4 Bézier 曲线
一.作业描述
二.作业解析
1.递归Bezier实现代码
分析了下文档的意思,大概是用递归的方法实现De Casteljau算法。实现起来也比较简单,递归函数的递归出口在control_points中的点数为1时,返回求出的这个点,递归的代码如下所示。
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 (double t = 0.0; t <= 1.0; t += 0.001)
{
auto point= recursive_bezier(control_points,t);
std::cout << point.x << ", "<< point.y << ")" << '\n';
window.at<cv::Vec3b>(point.y, point.x)[1] = 255;
}
}
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> v;
for(int i=0;i<control_points.size()-1;i++)
{
cv::Point2f p=t*control_points[i]+(1-t)*control_points[i+1];
v.push_back(p);
}
return recursive_bezier(v,t);
}
直接调用原代码给出的native_bezier。
两个函数一起调用效果如下所示。
2.Bezier曲线反走样
直接绘制除的Bezier曲线存在走样的问题。
反走样的思路是计算九宫格中与当前点相邻的8个像素点坐标与当前点坐标距离,并根据距离设置颜色线性渐变(思路参考作业4(提高)含Bazier曲线的反走样处理)按照这个思路绘制的边缘效果比其他方法都更强一些。
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 (double t = 0.0; t <= 1.0; t += 0.001)
{
auto point= recursive_bezier(control_points,t);
std::cout << point.x << ", "<< point.y << ")" << '\n';
for(int i=-1;i<=1;i++){
for(int j=-1;j<=1;j++){
cv::Point2f t;
t.x=point.x+i;
t.y=point.y+j;
float d=sqrt(pow(t.x-((int)t.x+i)-0.5,2)+pow(t.y-((int)t.y+j)-0.5,2));
float ratio=1.0-sqrt(2)/3.0*d;
window.at<cv::Vec3b>(t.y, t.x)[1] = std::fmax(255*ratio,window.at<cv::Vec3b>(t.y, t.x)[1]);
}
}
// window.at<cv::Vec3b>(point.y, point.x)[1] = 255;
}
}
反走样效果如下所示,比起之前的效果要流畅很多。
边栏推荐
- Nexus Introduction and Xiaobai use idea Packaging and Upload to Nexus 3 private service detailed tutoriel
- 酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东
- Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion
- JS20 array flattening
- OpenHarmony如何启动FA(本地和远程)
- One year is worth ten years
- 畅玩集团冲刺港股:年营收2.89亿 刘辉有53.46%投票权
- What if the default browser cannot be set?
- 海思Hi3798MV100机顶盒芯片介绍[通俗易懂]
- Séparateur JS3 de niuke
猜你喜欢
Timing / counter of 32 and 51 single chip microcomputer
剑指 Offer 24. 反转链表
si446使用记录(一):基本资料获取
Qstype implementation of self drawing interface project practice (II)
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
剑指 Offer 27. 二叉树的镜像
Example nonlinear integer programming
Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion
13、Darknet YOLO3
Use of openpose
随机推荐
How to transfer business data with BorgWarner through EDI?
About me
vector的底层模拟实现
Experience home office, feel the completion of the project | community essay solicitation
伟立控股港交所上市:市值5亿港元 为湖北贡献一个IPO
一年頂十年
Sword finger offer 26 Substructure of tree
Dstat use [easy to understand]
ROS知识点——ros::NodeHandle n 和 nh(“~“)的区别
剑指 Offer 26. 树的子结构
TCP congestion control details | 2 background
Use of openpose
Introduction to Hisilicon hi3798mv100 set top box chip [easy to understand]
什么是敏捷开发流程
线性规划例题 投资的收益与风险
Nexus简介及小白使用IDEA打包上传到Nexus3私服详细教程
剑指 Offer 24. 反转链表
Connect Porsche and 3PL EDI cases
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst
几行代码搞定RPC服务注册和发现