Created
April 20, 2010 10:40
-
-
Save evilstreak/372293 to your computer and use it in GitHub Desktop.
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 points_on_a_line( from, to, gap ) { | |
// work out the difference in X and Y, and the hypotenuse | |
var dx = to.x - from.x, | |
dy = to.y - from.y, | |
h = Math.sqrt( dx*dx + dy*dy ) | |
points = [], | |
// work out what proportion of the hypotenuse each step will be | |
step = gap / h, | |
d = 0, | |
i = 0; | |
// for each step, add that proportion of dx and dy to the start position | |
while ( ( d += ( ++i * step ) ) < 1 ) { | |
points.push( { | |
x : from.x + d * dx, | |
y : from.y + d * dy | |
} ); | |
} | |
return points; | |
} |
robholland
commented
Apr 20, 2010
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment