|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Line Drawing Algorithm Explained |
|
![]() Jaytan Member since: 3/28/2005 From: USA |
||||
|
|
||||
Heres another implementation of the algorithm that is less easy to follow, but significantly more compact:
int dx = abs(x1 - x0),
dy = abs(y1 - y0);
bool steep = dy > dx;
if(steep)
{
Swap(dx, dy);
Swap(x0, z0);
Swap(x1, z1);
}
int error = 0,
de = dy,
&x = steep ? y0 : x0,
&y = steep ? x0 : y0,
xstep = (x0 < x1) ? 1 : -1,
ystep = (y0 < y1) ? 1 : -1;
Plot(x, y);
while(x0 != x1)
{
x0 += xstep;
error += de;
if( (error << 1) >= dx)
{
y0 += ystep;
error -= dx;
}
Plot(x, y);
}
|
||||
|
||||
![]() aymensan Member since: 9/25/2007 From: Lausanne |
||||
|
|
||||
| Thank you very much, I sought everywhere a simple explanation of this algorithm in french or in english and this one is the best I found. God bless. |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|