Last active
February 6, 2023 19:14
-
-
Save z1nc0r3/9552a002160fb2a4ed9dbb680932c0e2 to your computer and use it in GitHub Desktop.
DDA Line Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ddaLine(float xa, float ya, float xb, float yb) { | |
int dx = xb - xa, dy = yb - ya; | |
int k, steps; | |
float xinc, yinc, x = xa, y = ya; | |
if (abs(dx) > abs(dy)) { | |
steps = abs(dx); | |
} | |
else { | |
steps = abs(dy); | |
} | |
xinc = (float) dx / steps; | |
yinc = (float) dy / steps; | |
putPixel(x, y); | |
for (k = 0; k < steps; k++) { | |
x += xinc; | |
y += yinc; | |
putPixel(x, y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment