# “Location to location” algorithm?

Lets say I have two locations, each one with X, Y, Z, and a int. Each location represents one cube in a 1000 x 1000 world. Lets say I had one location at 500, 343, 284, with an int 1. Another one at 800, 100, 212, with an int 3. Lets say I wanted to make a whole cube, where location one is at one corner, and the other one is at the far other corner of the cube. Now lets say I want to take every block in that cube and change the int to 0. What algorithm would let me calculate which pixels are in the cube even though each location could be anywhere within the area of the world. How?

-
Welcome to math.SE: please note that questions about algorithm implementation and/or design are better suited to StackOverflow. As a reference, here is the relevant FAQ. –  A.P. May 4 '13 at 8:11
Where are the pixels located with respect to the cube? –  robjohn May 4 '13 at 8:19
The problem isn't well specified. As bubba points out in a comment below, you've still got a degree of freedom in the orientation of the cube. –  Peter Taylor May 4 '13 at 9:56
It has been suggested that this question might be better suited for stackoverflow. We should vote to close if so. –  robjohn May 4 '13 at 11:39

If the locations are suitably indexed by x, y, z, then

for x = 500 to 800
for y = 100 to 343
for z = 212 to 284
intValue[x,y,z] = 0
end for
end for
end for


If they are not, then:

for each location in world
x = location.x
y = location.y
z = location.z
insideX = (x > 500) && (x < 800)
insideY = (y > 100) && (y < 343)
insideZ = (z > 212) && (y < 284)
if (insideX && insideY && insideZ) location.intValue = 0
end for


This code is written for clarity rather than efficiency. It could be optimized to exit early if any of the "inside" tests return "false", of course.

Also, I assumed you didn't really mean "cube" (which is a shape whose sides have equal lengths). Instead, I assumed you were just talking about a block-shaped thing with sides parallel to the x,y,z axes.

-
There's only one example in the question, and it's not axis-aligned. –  Peter Taylor May 4 '13 at 8:41
I assumed that "cube" meant parallelipiped, and that it was axis-aligned. If the question really is about a cube, then it can't be answered, because obviously thare are infinitley many cubes having thr given two points as opposite corners. –  bubba May 4 '13 at 8:51
sorry for the typos (can't see properly today). What I meant to write was "there are infinitely many cubes having the given two points ... etc." –  bubba May 4 '13 at 9:02