当前位置:网站首页>【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;
}
}
反走样效果如下所示,比起之前的效果要流畅很多。
边栏推荐
- 线性规划例题 投资的收益与风险
- 什么是敏捷开发流程
- ETH数据集下载及相关问题
- [fluent] dart data type map type (create map set | initialize map set | traverse map set)
- 一年顶十年
- Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia
- traceroute命令讲解
- Si446 usage record (II): generate header files using wds3
- IDEA2021.1 安装教程
- Exploration of mobile application performance tools
猜你喜欢

Qwebengineview crash and alternatives

Si446 usage record (I): basic data acquisition

线性规划例题 投资的收益与风险
![[essay solicitation activity] Dear developer, RT thread community calls you to contribute](/img/31/11409606718e0f4837f4cc572172a3.png)
[essay solicitation activity] Dear developer, RT thread community calls you to contribute

剑指 Offer 27. 二叉树的镜像

From collection to output: inventory those powerful knowledge management tools - inventory of excellent note taking software (4)

绿竹生物冲刺港股:年期内亏损超5亿 泰格医药与北京亦庄是股东

剑指 Offer 24. 反转链表

How to transfer business data with BorgWarner through EDI?

智能垃圾桶(五)——点亮OLED
随机推荐
Uniapp H5 page calls wechat payment
Smart trash can (V) - light up OLED
几行代码搞定RPC服务注册和发现
Believe in yourself and finish the JVM interview this time
深度之眼(二)——矩阵及其基本运算
云通信接口更新迭代——SUBMAIL API V4正式上线
Qwebengineview crash and alternatives
[fluent] dart data type map type (create map set | initialize map set | traverse map set)
SAP Commerce Cloud 架构概述
选择 SAP Spartacus 作为 SAP Commerce Cloud Storefront 实现框架的五个理由
人生的开始
Helm kubernetes package management tool
简单线性规划问题
Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
Visibilitychange – refresh the page data when the specified tab is visible
Simple linear programming problem
One year is worth ten years
PCL知识点——体素化网格方法对点云进行下采样
What is agile development process
Nexus Introduction and Xiaobai use idea Packaging and Upload to Nexus 3 private service detailed tutoriel