当前位置:网站首页>[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 .
边栏推荐
- 977. Square of ordered array
- [how is the network connected] Chapter 6 requests arrive at the server and respond to the client (end)
- What should we pay attention to in the development process of Yingguang single chip microcomputer?
- 原厂原装 应广单片机PMS134方案开发应用案例
- Develop a controller that prohibits deleting namespaces
- Modbus协议通信异常
- 515. 在每个树行中找最大值
- Wasserstein Slim GAIN with Clipping Penalty(WSGAIN-CP)介绍及代码实现——基于生成对抗网络的缺失数据填补
- 透过华为军团看科技之变(六):智慧公路
- The price is only 40 yuan. Pico development board of raspberry pie is added with WiFi module, and it is out of stock as soon as it comes into the market
猜你喜欢

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

Keras深度学习实战——基于VGG19模型实现性别分类

1288_FreeRTOS中vTaskResume()接口以及中断安全版本接口实现分析

Mb10m-asemi rectifier bridge mb10m
![[how is the network connected] Chapter 4 explores access networks and network operators](/img/50/d16f4dca571a5a5f9b20fada289d45.png)
[how is the network connected] Chapter 4 explores access networks and network operators

【網絡是怎樣連接的】第六章 請求到達服務器以及響應給客戶端(完結)

【曆史上的今天】7 月 2 日:BitTorrent 問世;商業系統 Linspire 被收購;索尼部署 PlayStation Now

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

【Golang | gRPC】使用gRPC实现简单远程调用

aloam 代码阅读与总结
随机推荐
Deep understanding of ThreadLocal
【Zuul】com.netflix.zuul.exception.ZuulException: Hystrix Readed time out
辉芒微IO单片机FT60F010A-URT
Wasserstein Slim GAIN with Clipping Penalty(WSGAIN-CP)介绍及代码实现——基于生成对抗网络的缺失数据填补
切换变换的时候记得使用三元表达式
PHP gets the number of days, hours, minutes and seconds between the two timestamps
Taiwan Feiling fm8pb513b MCU provides MCU program development product design
freemarker+poi实现动态生成excel文件及解析excel文件
【Zuul】com. netflix. zuul. exception. ZuulException: Hystrix Readed time out
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
原装应广单片机 MCU芯片PMS152 SOP8封装 单片机开发
Ora-19838 -- restore control files to the standby database
Turn off the xshell connection server and the running jar package will stop automatically
【网络是怎么连接的】第四章 探索接入网和网络运营商
详解Kubernetes网络模型
Outsourcing for five years, abandoned
应广单片机开发 工规 PMC131 带AD芯片检测电池电压单片机SOP8/14
应广PMC131 SOP16 16pin八位单片机
Edgenext hit a mixed punch: a lightweight architecture integrating CNN and transformer
The price is only 40 yuan. Pico development board of raspberry pie is added with WiFi module, and it is out of stock as soon as it comes into the market