Created
September 29, 2014 12:48
-
-
Save luthfianto/8eb8c76c85f00477329c to your computer and use it in GitHub Desktop.
Digital Differential Analyzer in JavaScript
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
function dda(x0, y0, x1, y1) | |
{ | |
const dx = x1 - x0, | |
dy = y1 - y0, | |
s = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy), | |
xi = dx * 1.0 / s, | |
yi = dy * 1.0 / s | |
var x = x0, | |
y = y0, | |
out= [] | |
out.push({x: x0, y: y0}); | |
for (var i = 0; i < s; i++) { | |
x += xi; | |
y += yi; | |
out.push({x: x, y: y}); | |
} | |
return out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment