当前位置:网站首页>[games101] operation 4 B é zier curve
[games101] operation 4 B é zier curve
2022-07-02 18:00:00 【VV is vv】
【GAMES101】 Homework 4 Bézier curve
One . Job description


Two . Homework analysis
1. recursive Bezier Implementation code
Analyzed the meaning of the next document , It is probably achieved by recursion De Casteljau Algorithm . It's easy to implement , The recursive exit of recursive function is control_points The number of points in is 1 when , Return to the calculated point , The recursive code is as follows .
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);
}
Directly call the native_bezier.
The effect of calling the two functions together is as follows .
2.Bezier Curve anti aliasing
Directly draw divided Bezier The curve has the problem of aliasing .

The idea of anti aliasing is to calculate the adjacent to the current point in the Jiugong lattice 8 Distance between pixel coordinates and current point coordinates , And set the color linear gradient according to the distance ( Train of thought reference Homework 4( Improve ) contain Bazier Anti aliasing of curve ) The edge effect drawn according to this idea is stronger than other methods .
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;
}
}
The anti aliasing effect is as follows , The effect is much smoother than before .
边栏推荐
- Viewing technological changes through Huawei Corps (VI): smart highway
- android之循环定时器实现,实现定Android时缓存清理
- pytorch支持32位吗?
- Modbus协议通信异常
- 我的创作纪念日
- [target tracking] |siamfc
- Does pytorch support 32 bits?
- [target tracking] | data set summary
- [nonlinear control theory]7_ High gain and High Frequency
- 开发一个禁止删除namespace的控制器
猜你喜欢

MySQL --- 數據庫的基本操作

Keras' deep learning practice -- gender classification based on vgg19 model

一日2篇Nature!中科大校友段镶锋团队纳米材料新成果,曾是贝尔比奖章第三位华人得主...

MySQL advanced - transaction and index

Virtual lab basic experiment tutorial -7 Polarization (2)

Microsoft LDAP 配置页中输入有效的用户名及密码,microsoft ldap 配置页中输入有效的用户名

售价仅40元,树莓派Pico开发板加入WiFi模块,刚上市就脱销

每日一题——倒置字符串

Yingguang single chip microcomputer development specification pmc131 with AD chip to detect battery voltage single chip microcomputer sop8/14

MB10M-ASEMI整流桥MB10M
随机推荐
【曆史上的今天】7 月 2 日:BitTorrent 問世;商業系統 Linspire 被收購;索尼部署 PlayStation Now
外包干了五年,废了...
Two pieces of nature a day! Duan Fengfeng, an alumnus of the University of science and technology of China, was the third Chinese winner of the belby medal
[today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now
Finally detailed explanation
Troubleshooting ideas that can solve 80% of faults
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
EdgeNeXt打出了一套混合拳:集CNN与Transformer于一体的轻量级架构
Calculation of favorable comment rate
嵌入式 ~ 介绍
POJ - 1458 common subsequence (longest common subsequence)
In Linux, MySQL sets the job task to start automatically
Virtual lab basic experiment tutorial -7 Polarization (1)
【网络是怎么连接的】第四章 探索接入网和网络运营商
【Golang | gRPC】使用gRPC实现简单远程调用
体验一下阿里云文字识别OCR
vimium映射键
切换变换的时候记得使用三元表达式
Taiwan Feiling fm8pb513b MCU provides MCU program development product design
辉芒微IO单片机FT60F11F-MRB