Say we have a space of dimension $D$. Say we have a $D$-cube of side $l$ centered at the origin and inside it we have a point $P\in \mathbb{R}^D$ and a collection of $D-1$ angles $\phi_1, \phi_2, \ldots \phi_{D-1}$. Then, say we have a line $r$ that is defined by the point $P$ and the angles.

Is there any nice formula to determine the points where the line and the cube will intersect?


Convert your angles $\phi_1, \ldots \phi_{d-1}$ to a unit vector $v$. Then solve $p_i + t v_i = \pm 1$ for each $i=1,\ldots,d$. This yields the scale factor $t$ that reaches the $i$-th hyperplane above $+$ or below $-$. The minimum positive $t$ of all these $2d$ solutions is the first cube face hit by $p + t v = u$.

Then scale by $l/2$.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.