How to construct an algorithm to move along a discrete grid at constant steps?

37 Views Asked by At

Assume we have a tessellation of cubes of length one of a 3D space.

We have a starting point $P$ and a direction $\vec V$ of length one.

Our goal is to move the point $P$ by direction $\vec V$ such that $P$ now lies exactly on the closest edge of the grid along that direction. In other words, in 2D, if we have the point (0.5,0.5) and the direction (0.1,0.1) the result should be the point (1,1). If it was (0.5,0.5) and (1.0,0) the result should be (1,0.5) and so on...

This needs to be done in constant time (i.e $O(1)$).

What tools can I use to solve this?