bresenham 算法生成直线
struct Point
{
Point()
{
posx = 0;
posy = 0;
}
Point(int x, int y)
{
posx = x;
posy = y;
}
int posx;
int posy;
};
void bresenham(int x1, int y1, int x2, int y2, vector<Point>& path)
{
path.clear();
int dx = abs(x2 - x1);
int dy = abs(y2 - y1);
int inc_x = (x2 > x1) ? 1 : -1;
int inc_y = (y2 > y1) ? 1 : -1;
int eps = 0;
Point pos(x1, y1);
path.push_back(pos);
int x = x1;
int y = y1;
if(dx > dy)
{
for(x = x1; x != x2; x += inc_x)
eps += dy;
if((eps << 1) >= dx)
{
y += inc_y;
eps -= dx;
}
pos.posx = x;
pos.posy = y;
path.push_back(pos);
}
}
else
{
for(y = y1; y != y2; y+= inc_y)
{
eps += dx;
if((eps << 1) >= dy)
{
x += inc_x;
eps -= dy;
}
pos.posx = x;
pos.posy = y;
path.push_back(pos);
}
}
pos.posx = x;
pos.posy = y;
path.push_back(pos);
}
最新文章
- swift 的枚举、结构体、类
- Hadoop学习笔记—12.MapReduce中的常见算法
- [转]PowerDesigner设置集锦
- EF架构~基于EF数据层的实现
- ACM spiral grid
- Nginx学习记录
- [转]Hibernate不能自动建表解决办法及Hibernate不同数据库的连接及SQL方言
- Qt之事件系统
- 【转】一道SQL SERVER DateTime的试题
- Docker搭建MySQL服务
- Emoji表情符号兼容方案(适用ios,android,wp等平台)
- SNA社交网络算法
- asp.net textbox keyup事件触发后台的textchange事件
- android AsyncTask介绍 转载
- 第4章 同步控制 Synchronization ----死锁(DeadLock)
- django之快速分页
- this.$router.push、replace、go的区别
- Nginx 参数配置相关
- kali linux 64bit 2019.1a下启动bbqsql:No module named coros
- 51nod 1069 Nim游戏 + BZOJ 1022: [SHOI2008]小约翰的游戏John(Nim游戏和Anti-Nim游戏)