Bresenham算法
来源:互联网 发布:centos yum源下载 编辑:程序博客网 时间:2024/04/28 17:34
先前弄STM32驱动LCD时曾见Bresenham算法,最近学习opencv时应需要特意学习了此算法(参考了《计算机图形学》),个人认为此算法的精髓在于得到一个决策参数,来判断下一个像素点的位置,从而避免了大量的浮点运算,提高了程序的运行速度。下面是画线的代码:
画线算法:
void BresenhamLine(int x0, int y0, int xe, int ye, vector<Point2i>& pointbuf){int temp;int dx = abs(xe - x0);int dy = abs(ye - y0);int cdx, cdy;/***********斜率大于1*******/if (dx < dy)//坐标转换{swap_int(&x0, &y0);swap_int(&xe, &ye);cdx = dy;cdy = dx;}else {cdx = dx;cdy = dy;}/***************************/int count = cdx,sign = 1;//斜率为负标志位if (x0 > xe){swap_int(&x0, &xe);swap_int(&y0, &ye);}if (y0 > ye) {x0 = xe;y0 = ye;sign = -1;}int p = 2 * cdy - cdx;if (dy>dx)//是否进行了坐标转换SetPoint(y0, x0, pointbuf);elseSetPoint(x0, y0, pointbuf);while (count--){x0 += sign;if (p < 0)p += 2 * cdy;else{y0++;p += 2 * cdy - 2 * cdx;}if (dy>dx)//是否进行了坐标转换SetPoint(y0, x0, pointbuf);elseSetPoint(x0, y0, pointbuf);}}
void circle(int x0, int y0, int r, vector<Point2i>& pointbuf){int p = 1 - r;int x = 0, y = r;SetPoint(x0, y + y0, pointbuf);SetPoint(x0, y0 - y, pointbuf);SetPoint(x0 - y, y0, pointbuf);SetPoint(x0 + y, y0, pointbuf);while (x < y){x++;if (p < 0)p += 2 * x + 1;else{p += 1 + 2 * (x - y);y--;}CirclePlot(x, y, x0, y0, pointbuf);}}
0 0
- Bresenham算法
- Bresenham算法
- Bresenham算法
- bresenham算法
- Bresenham算法
- Bresenham算法
- Bresenham算法
- Bresenham算法
- Bresenham算法
- Bresenham算法
- bresenham算法
- 画线算法-Bresenham算法
- Bresenham 画线算法
- Bresenham高效画线算法
- Bresenham 画线算法
- Bresenham 直线算法
- Bresenham画圆算法
- Bresenham 画线算法
- apt常用语法
- 关于UGUI的一些小小的拓展,给以后自己Mark一下
- 几种内网穿透方法总结
- VSCode多开及其它环境对比
- anjularjs 点击打开新窗口
- Bresenham算法
- ZooKeeper的核心特性
- consign issue release bpa
- C语言打印沙漏
- SAP ME概念
- Spring3.2下使用JavaMailSenderImpl类发送邮件
- 文件上传--测试用例1
- Linux设备驱动归纳总结(七):2.内核定时器
- Java Reflection(一):Java反射指南