当前位置:网站首页>[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 .
边栏推荐
- Daily question - xiaolele changes the number
- My creation anniversary
- Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
- Pms150c Yingguang MCU development case
- Development and application case of pms134 scheme of Yingguang single chip microcomputer with original packaging
- Yingguang single chip microcomputer (MCU popular science)
- Solution pour arrêter automatiquement les paquets Jar en cours d'exécution en éteignant le serveur de connexion xshell
- Troubleshooting ideas that can solve 80% of faults
- 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
- Linux中,mysql设置job任务自动启动
猜你喜欢
【网络是怎么连接的】第四章 探索接入网和网络运营商
ORA-19838 -- 恢复控制文件到备库
Daily question - inverted string
MySQL --- 数据库的基本概念
Troubleshooting ideas that can solve 80% of faults
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
Finally detailed explanation
pytorch支持32位吗?
Keras深度学习实战——基于VGG19模型实现性别分类
切换变换的时候记得使用三元表达式
随机推荐
原装应广单片机 MCU芯片PMS152 SOP8封装 单片机开发
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
透过华为军团看科技之变(六):智慧公路
What should we pay attention to in the development process of Yingguang single chip microcomputer?
In Linux, MySQL sets the job task to start automatically
Daily question - xiaolele changes the number
辉芒微IO单片机FT60F011A-RB
Aloam code reading and summary
Finally detailed explanation
JDBC
Many scenic spots are temporarily closed due to the typhoon. The provincial culture and tourism department reminds you to pay attention to safety!
【Zuul】com. netflix. zuul. exception. ZuulException: Hystrix Readed time out
Redisson high performance redis distributed lock source code analysis
我的创作纪念日
Huimang micro IO MCU ft60f011a-rb
Songhan sn8p2511 sop8 single chip microcomputer can be used for burning, providing single chip microcomputer scheme development and single chip microcomputer decryption
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
MySQL advanced - transaction and index
台湾飞凌FM8PB513B单片机提供单片机方案开发 产品设计
义隆EM78P153K DIP14单片机 MCU