当前位置:网站首页>【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;
}
}
反走样效果如下所示,比起之前的效果要流畅很多。
边栏推荐
- 海思Hi3798MV100机顶盒芯片介绍[通俗易懂]
- 简单介绍BASE64Encoder的使用
- Sword finger offer 25 Merge two sorted linked lists
- dstat使用[通俗易懂]
- Vscode + eslint configuration
- A case study of college entrance examination prediction based on multivariate time series
- Timing / counter of 32 and 51 single chip microcomputer
- ssb门限_SSB调制「建议收藏」
- Experience home office, feel the completion of the project | community essay solicitation
- IDEA2021.1 安装教程
猜你喜欢
Experience home office, feel the completion of the project | community essay solicitation
After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
Microservice architecture practice: Construction of scalable distributed database cluster
Blog theme "text" summer fresh Special Edition
剑指 Offer 25. 合并两个排序的链表
Timing / counter of 32 and 51 single chip microcomputer
A few lines of code to complete RPC service registration and discovery
Sword finger offer 27 Image of binary tree
Jiuxian's IPO was terminated: Sequoia and Dongfang Fuhai were shareholders who had planned to raise 1billion yuan
深度之眼(三)——矩阵的行列式
随机推荐
IPtables中SNAT、DNAT和MASQUERADE的含义
traceroute命令讲解
What is agile development process
几行代码搞定RPC服务注册和发现
executescalar mysql_ ExecuteScalar()
云通信接口更新迭代——SUBMAIL API V4正式上线
What if the default browser cannot be set?
Vscode + eslint configuration
Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
Update iteration of cloud communication interface -- the official launch of subail API V4
Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
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
Introduction to nexus and detailed tutorial of Xiaobai using idea to package and upload to nexus3 private server
Goodbye, shucang. Alibaba's data Lake construction strategy is really awesome!
Solving simple differential equations
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
Timing / counter of 32 and 51 single chip microcomputer
链表求和[dummy+尾插法+函数处理链表引用常见坑位]
剑指 Offer 24. 反转链表
si446使用记录(一):基本资料获取