当前位置:网站首页>【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;
}
}
反走样效果如下所示,比起之前的效果要流畅很多。
边栏推荐
- Sword finger offer 24 Reverse linked list
- Microservice architecture practice: Construction of highly available distributed file system fastdfs architecture
- Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers
- 海思Hi3798MV100机顶盒芯片介绍[通俗易懂]
- Leetcode question brushing record | 933_ Recent requests
- Jiuxian's IPO was terminated: Sequoia and Dongfang Fuhai were shareholders who had planned to raise 1billion yuan
- Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
- 畅玩集团冲刺港股:年营收2.89亿 刘辉有53.46%投票权
- visibilitychange – 指定标签页可见时,刷新页面数据
- Introduction to Hisilicon hi3798mv100 set top box chip [easy to understand]
猜你喜欢
Does digicert SSL certificate support Chinese domain name application?
Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
13、Darknet YOLO3
A few lines of code to complete RPC service registration and discovery
从收集到输出:盘点那些强大的知识管理工具——优秀笔记软件盘点(四)
綠竹生物沖刺港股:年期內虧損超5億 泰格醫藥與北京亦莊是股東
Geoserver: publishing PostGIS data sources
畅玩集团冲刺港股:年营收2.89亿 刘辉有53.46%投票权
How to transfer business data with BorgWarner through EDI?
Eth data set download and related problems
随机推荐
Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
Chmod command principle and usage details [easy to understand]
Green bamboo biological sprint Hong Kong stocks: loss of more than 500million during the year, tiger medicine and Beijing Yizhuang are shareholders
牛客 JS3 分隔符
executescalar mysql_ExecuteScalar()
Update iteration of cloud communication interface -- the official launch of subail API V4
Qstype implementation of self drawing interface project practice (II)
ThreadLocal
Microservice architecture practice: Construction of highly available distributed file system fastdfs architecture
How to quickly distinguish controlled components from uncontrolled components?
Eth data set download and related problems
什么是软件开发中的 green field 和 brown field 模式 - 绿地开发和棕地开发
剑指 Offer 24. 反转链表
Flutter: 动作反馈
Eye of depth (III) -- determinant of matrix
剑指 Offer 22. 链表中倒数第k个节点
About me
si446使用记录(二):使用WDS3生成头文件
SSB threshold_ SSB modulation "suggestions collection"
ETH数据集下载及相关问题