1
$\begingroup$

I am in a middle of a grid of 8X8 . Each box of grid is a square with side of 80 units. Suppose my current coordinates are 594,422 . How many boxes will i have to move to enter the square that contains the coordinates 594,24 ?

The grid starts from the coordinates 350,20 as shown here.

enter image description here

The answer of the above problem is : I will have to move 5 boxes to capture the coordinate 594,24. But how can i generalize this result ? Any expression that can evaluate this is what i want ? Please also show the logic i.e where does the expression come from .

If my current coordinate is x,y and i have to capture x,q how many boxes will i have to move to do that ? Getting more general , if my current coordinate is x,y and i have to capture p,q how many boxes will i have to move to do that ?

In this grid x and y increase as shown.

  • 0
    I edited the title to make it more informative, but there is still room for improvement, should anyone like to try.2011-10-21

1 Answers 1

2

You can do this in two steps: First figure out how to get from point coordinates to box coordinates; then just subtract the box coordinates corresponding to the source and destination. To find the box coordinates corresponding to given point coordinates, first subtract the coordinates $350,20$ of the origin. Then the box coordinate is just the result of dividing that by the box size, $80$, with integer division. In a programming language where / applied to integers results in integer division, you could write this as

bx = (x - 350) / 80; by = (y -  20) / 80; 

In mathematical notation, this would be

$x_b = \left\lfloor\frac{x-350}{80}\right\rfloor\;,$ $y_b = \left\lfloor\frac{\,y\,\;-\;\,20\,}{80}\right\rfloor\;,$

where the floor function $\lfloor\cdot\rfloor$ yields the greatest integer not greater than its argument.

  • 0
    OOPs, I am really sorry, I am typing on a horrible keyboard!2011-10-23