I want to get all the x,y,z coordinates between 2 given points, on a straight line. I need to be able to do this in JavaScript for checking whether a projectile collides in my game.
So, for example:
Point 1: (0,0,0) Point 2: (2,2,2) -> 0,0,0 - 1,1,1, 2,2,2
Edit, here is working code for anybody who is lost.
def ROUND(a):
return int(a + 0.5)
def drawDDA(x1,y1,z1,x2,y2,z2):
x,y,z = x1,y1,z1
length = (x2-x1) if (x2-x1) > (y2-y1) else (y2-y1) if (y2-y1) > (z2-z1) else (z2-z1)
dx = (x2-x1)/float(length)
dy = (y2-y1)/float(length)
dz = (z2-z1)/float(length)
print (ROUND(x),ROUND(y),ROUND(z))
for i in range(length):
x += dx
z += dz
y += dy
print(ROUND(x),ROUND(y),ROUND(z))
drawDDA(0,1,2,10,11,12)