Lesson 1: Bresenham’s Line Drawing Algorithm
来源:互联网 发布:jdk1.7 mac 编辑:程序博客网 时间:2024/06/06 19:29
1.
void line(int x0, int y0, int x1, int y1, TGAImage &image, TGAColor color) { for (float t=0.; t<1.; t+=.01) { int x = x0*(1.-t) + x1*t; int y = y0*(1.-t) + y1*t; image.set(x, y, color); }}
2.
void line(int x0, int y0, int x1, int y1, TGAImage &image, TGAColor color) { for (int x=x0; x<=x1; x++) { float t = (x-x0)/(float)(x1-x0); int y = y0*(1.-t) + y1*t; image.set(x, y, color); } }3.void line(int x0, int y0, int x1, int y1, TGAImage &image, TGAColor color) { bool steep = false; if (std::abs(x0-x1)<std::abs(y0-y1)) { // if the line is steep, we transpose the image std::swap(x0, y0); std::swap(x1, y1); steep = true; } if (x0>x1) { // make it left−to−right std::swap(x0, x1); std::swap(y0, y1); } for (int x=x0; x<=x1; x++) { float t = (x-x0)/(float)(x1-x0); int y = y0*(1.-t) + y1*t; if (steep) { image.set(y, x, color); // if transposed, de−transpose } else { image.set(x, y, color); } } }4.void line(int x0, int y0, int x1, int y1, TGAImage &image, TGAColor color) { bool steep = false; if (std::abs(x0-x1)<std::abs(y0-y1)) { std::swap(x0, y0); std::swap(x1, y1); steep = true; } if (x0>x1) { std::swap(x0, x1); std::swap(y0, y1); } int dx = x1-x0; int dy = y1-y0; float derror = std::abs(dy/float(dx)); float error = 0; int y = y0; for (int x=x0; x<=x1; x++) { if (steep) { image.set(y, x, color); } else { image.set(x, y, color); } error += derror; if (error>.5) { y += (y1>y0?1:-1); error -= 1.; } } }5.void line(int x0, int y0, int x1, int y1, TGAImage &image, TGAColor color) { bool steep = false; if (std::abs(x0-x1)<std::abs(y0-y1)) { std::swap(x0, y0); std::swap(x1, y1); steep = true; } if (x0>x1) { std::swap(x0, x1); std::swap(y0, y1); } int dx = x1-x0; int dy = y1-y0; int derror2 = std::abs(dy)*2; int error2 = 0; int y = y0; for (int x=x0; x<=x1; x++) { if (steep) { image.set(y, x, color); } else { image.set(x, y, color); } error2 += derror2; if (error2 > dx) { y += (y1>y0?1:-1); error2 -= dx*2; } } }
0 0
- Lesson 1: Bresenham’s Line Drawing Algorithm
- Bresenham's line and circle algorithm
- Bresenham line algorithm
- Command Line -- Lesson 1
- Line Drawing
- Drawing Line Animation
- Tarjan’s off-line lowest common ancestors algorithm
- Command Line -- Lesson 2
- Command Line -- Lesson 3
- [Drawing]Amiy's trip
- Lesson 4 Part 1 Newton's method
- Algorithm: Euclid's Algorithm
- 【Algorithm】Manacher's Algorithm
- using matlab drawing line graph for latex
- [翻译]扫描线算法(Line Sweep Algorithm)(1)
- 图算法(1):Dijkstra's algorithm
- Algorithm: Extended Euclid's Algorithm
- 【Android Training UI】创建自定义Views(Lesson 2 - 自定义Drawing)
- 根据ASCII找出乱码字符
- 下载代码添加 SSH Public Key的方法
- PAT--1112. Stucked Keyboard
- Handler导致的内存泄露问题
- 自动分析工具:数据科学家职业的终结者
- Lesson 1: Bresenham’s Line Drawing Algorithm
- android四大组件之一Service
- 对于树状数组的理解
- Java垃圾收集学习笔记
- Swift - final关键字的介绍,以及使用场景
- CVE-2016-3115 - OpenSSH <=7.2p1 xauth injection
- 常用Linxu系统监控命令
- DataGridView 行列
- js中判断数据为空