当前位置:网站首页>[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 .
边栏推荐
- Microsoft LDAP 配置页中输入有效的用户名及密码,microsoft ldap 配置页中输入有效的用户名
- In Linux, MySQL sets the job task to start automatically
- 应广单片机开发流程需要注意哪些?
- Alibaba cloud sub account - Permission Policy - full control permission granted to an account and an OSS bucket
- Tips for self defined packaging of Yingguang SCM 003 burner
- 详解Kubernetes网络模型
- Atcoder beginer contest 237 VP supplement
- 辉芒微IO单片机FT60F11F-MRB
- 【網絡是怎樣連接的】第六章 請求到達服務器以及響應給客戶端(完結)
- Longest non repeating subarray
猜你喜欢

应广单片机开发 工规 PMC131 带AD芯片检测电池电压单片机SOP8/14

Laravel文档阅读笔记-Custom Authentication Login And Registration Using Laravel 8

wait_ for_ Gap -- restore archive from primary archive to secondary Archive

体验一下阿里云文字识别OCR

Finally detailed explanation
![[target tracking] |siamfc](/img/40/3419761d2eb7f1193b699cdd431761.png)
[target tracking] |siamfc

Editor编辑器扩展在Scene View添加按钮和logo

Bluetooth technology | new working mode of wearable devices of the Internet of things, and Bluetooth ble helps the new working mode

详解Kubernetes网络模型

What is the experience of maintaining Wanxing open source vector database
随机推荐
MySQL -- basic concept of database
售价仅40元,树莓派Pico开发板加入WiFi模块,刚上市就脱销
Modbus协议通信异常
Calculation of favorable comment rate
Solution pour arrêter automatiquement les paquets Jar en cours d'exécution en éteignant le serveur de connexion xshell
vimium映射键
My creation anniversary
HDU - 1114 Piggy Bank (full backpack)
Huimang micro IO MCU ft60f010a-urt
[how is the network connected] Chapter 6 requests arrive at the server and respond to the client (end)
使用Zadig从0到1搭建持续交付平台
读写 XML/JSON/INI 和 UBJSON 等格式的数据文件的统一接口
Easyai notes - machine learning
Easyai notes - deep learning
把xshell連接服務器關掉,運行的jar包就自動停止的解决方案
Ora-19838 -- restore control files to the standby database
Deep understanding of ThreadLocal
515. Find the maximum value in each tree row
Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
Troubleshooting ideas that can solve 80% of faults