0
$\begingroup$

In a specific scenario there is a cube with 1 unit of size in each axis. One of the vertices of this cube is placed in the origin point and all others points are in the positive area of each axis like that:

Some definitions:

  • $A$ is a vertex of the $cube$ with the coordinates $(a_x, a_y, a_z)$.

  • $G$ is a point belonging to the cube (inside or tangent to the cube surface) with the coordinates $(g_x, g_y, g_z)$.

  • $r$ the straight that passes in $A$ and $G$.

  • $F$ is the farest point from $A$ that belongs to $r$ and the $cube$ at the same time.

Check the draw bellow:

Question:

How can I find the F point?

  • 0
    Where is $B$ in your drawing? Did you mean $G$?2017-02-01
  • 0
    Yes B = G, sorry, I will update.2017-02-01

1 Answers 1

0

Somewhat generically:

a line through two points $A$ and $B$ has parametric formula $f(t) = A + (B-A)t$.

A plane of form $C\cdot x=k$ and this line meet at $C\cdot(A+(B-A)t)=k$, which can be transformed to $$t=\frac{k - C\cdot A}{C\cdot(B-A)}$$.

For a cube like this, the planes are $-x=0$, $-y=0$, $-z=0$, $x=1$, $y=1$, and $z=1$. In order to find the intersections between the cube and the line, we will find the intersections of these planes with the line, as $t$ values. Then, sort the planes and $t$ values by the $t$ values; if every dimension the line moves in appears once in the first half of the list, then the line passes through the cube and the line enters the cube at the $t$ value just before the midway point on the list and exits the cube at the $t$ value just after.

This last trick only works if you know that every face in your polytope has a parallel counterpart; otherwise you have to check whether a point at $t=-\infty$ gives $C\cdot(A+(B-A)t)$ means outside -- and then scan through the sorted list of $t$ values and planes to see whether all out-in transitions happen before any in-out transitions; the last out-in transition is where the line enters the polytope, the first in-out transition is where the line exits.

In your case, you will find that three of the $t$ values are $0$, and the other three are positive. The smallest positive $t$ value gives the point where the line exits the cube.