当前位置:网站首页>【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;
}
}
反走样效果如下所示,比起之前的效果要流畅很多。
边栏推荐
- Eye of depth (II) -- matrix and its basic operations
- 选择 SAP Spartacus 作为 SAP Commerce Cloud Storefront 实现框架的五个理由
- One year is worth ten years
- Income and risk of linear programming example investment
- Sword finger offer 27 Image of binary tree
- Goodbye, shucang. Alibaba's data Lake construction strategy is really awesome!
- 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
- 线性规划例题 投资的收益与风险
- Vscode knowledge points - Common Errors
- visibilitychange – 指定标签页可见时,刷新页面数据
猜你喜欢

TCP拥塞控制详解 | 2. 背景

深度之眼(三)——矩阵的行列式

Si446 usage record (II): generate header files using wds3

Win10 system uses pip to install juypter notebook process record (installed on a disk other than the system disk)

剑指 Offer 21. 调整数组顺序使奇数位于偶数前面

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

easyswoole3.2重启不成功

Blog theme "text" summer fresh Special Edition

Use the API port of the bridge of knowledge and action to provide resources for partners to access

Sword finger offer 24 Reverse linked list
随机推荐
ROS知识点——消息过滤器 ( message_filters)
Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers
Chmod command principle and usage details [easy to understand]
Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion
Use of openpose
深度之眼(三)——矩阵的行列式
Smart trash can (V) - light up OLED
IDEA2021.1 安装教程
Introduction to Hisilicon hi3798mv100 set top box chip [easy to understand]
Introduce the scrollintoview() method attribute in detail
SAP Commerce Cloud Storefront 框架选型:Accelerator 还是 Spartacus?
From collection to output: inventory those powerful knowledge management tools - inventory of excellent note taking software (4)
Eth data set download and related problems
牛客 JS3 分隔符
Green bamboo biological sprint Hong Kong stocks: loss of more than 500million during the year, tiger medicine and Beijing Yizhuang are shareholders
ROS知识点——ros::NodeHandle n 和 nh(“~“)的区别
Uniapp H5 page calls wechat payment
Schoolbag novel multithreaded crawler [easy to understand]
人生的开始
Microservice architecture practice: Construction of highly available distributed file system fastdfs architecture