Find the point of a plane where vector crosses cube wall

geometry

I'm creating $3D$ cube of elements that should rotate around axis. I have the axis but it is too long and is only suitable for a sphere because it's length is equal to the radius of a sphere. At the end of this topic there is a video that shows the rotation axis line segment that is out of bounds of the cube walls (cube planes). I need so the rotation axis last point would be in the appropriate plane of the cube wall (plane).

At any given time when rotation is stopped I have 8 points of the cube top coordinates. In the video it is blue and red points (projectiles):

Top blue: $P_1(x_1,y_1,z_1),\ P_2(x_2,y_2,z_2),\ P_3(x_3,y_3,z_3),\ P_4(x_4,y_4,z_4).$

In the same order bottom red: $\\ P_5(x_5,y_5,z_5),\ P_6(x_6,y_6,z_6),\ P_7(x_7,y_7,z_7),\ P_8(x_8,y_8,z_8).$

And I have rotation axis that is declared this way:

$
x_r=R\cdot \cos(\alpha)\sin(\phi), \\
y_r=R\cdot \sin(\alpha)\sin(\phi), \\
z_r=R\cdot \cos(\phi).
$

In the video azimuth is $\alpha$ and polar angle is $\phi$. Radius is R.
The rotation axis can be considered as a vector or line segment that goes from zero point to infinity. How long it continues I set through the radius. But now for a cube I'm going to change that. Radius is half of diagonal of a cube. Cube top eight points lengths from coordinate system origin are $1.$ And the length of a cube edge is $\frac{2}{\sqrt 3}.$

In general the vector that is going to cross planes equations are:

$
x_r=\cos(\alpha)\sin(\phi), \\
y_r=\sin(\alpha)\sin(\phi), \\
z_r=\cos(\phi).
$

Can it be used as a line equations?
This is the place where the information for my question ends. The video for the graph is this: Rotation line intersects plane

From this place I will try to find find the solution by myself

//—– 2019-06-09 ———-

Cube image

I need $x, y, z$ of the intersection point of the axis vector $\vec{k}$ and the cube face plane. I need parametric equations of the line which is expressed like this:

$
x_r=\cos(\alpha)\sin(\phi), \\
y_r=\sin(\alpha)\sin(\phi), \\
z_r=\cos(\phi).
$

The unit normal vector for the plane $(P_7,P_3,P_4)$ would be
$
\large \vec{n_u}= \bigg(\frac{x_3-x_1}{|n|}, \frac{y_3-y_1}{|n|}, \frac{z_3-z_1}{|n|}\bigg)=(a_1,b_1,c_1),\
|n|= \small\sqrt{(x_3-x_1)^2+(y_3-y_1)^2+(z_3-z_1)^2}=\large s.
$

Plane $(P_7,P_3,P_4)$ equation then: $a_1(x-x_3)+b_1(y-y_3)+c_1(z-z_3)=0.$

Line parametric equations are then $<x_rt, y_rt, z_rt>$

Point of intersection:

$
a_1(x_rt-x_3)+b_1(y_rt-y_3)+c_1(z_rt-z_3)=0,\\
a_1x_rt-a_1x_3+b_1y_rt-b_1y_3+c_1z_rt-c_1z_3=0,\ d=-a_1x_3-b_1y_3-c_1z_3,\\
a_1x_rt+b_1y_rt+c_1z_rt+d=0,\\
t(a_1x_r+b_1y_r+c_1z_r)+d=0,\\
\Large t=\frac{-d}{a_1x_r+b_1y_r+c_1z_r} \normalsize.
$

And by inserting this value to the Line parametric equations we get the point coordinates where the rotation axis intersects this particular plane.
There are six planes. The axis can intersect all of them or only two of them.
The main thing is to logically select the right cube wall. The intersection point must be on the appropriate plane and not too far from nearby points. If the distance between intersection point and a vertex is less than cube face plane diagonal then the intersection point is in that wall.

Best Answer

If you think about it a bit, you’ll see that the intersection points of the rotation axis with the cube are independent of its rotation—points along this axis are fixed. So, you only need to compute the intersection of the axis with the starting position of the cube, which we assume is centered on the origin and axis-aligned. The outward unit face normals are then $(\pm1,0,0)$, $(0,\pm1,0)$ and $(0,0,\pm1)$. By symmetry, you only need consider three faces that meet at a vertex, so you might as well pick the three standard unit basis vectors.

With a unit outward normal $\mathbf n$, the point-normal form of the equation of a face plane is $\mathbf n\cdot\mathbf x = s/2$, where $s$ is the cube’s side length. You have a unit direction vector $\mathbf k=(\cos\alpha\sin\phi,\sin\alpha\sin\phi,\cos\phi)$ for the rotation axis, so the distance to the intersection with the plane is given by the value of $t$ for which $\mathbf n\cdot(t\mathbf k)=s/2$, or $$t = {s\over2\mathbf n\cdot\mathbf k}.\tag{*}$$ However, the dot product of $\mathbf k$ with a standard basis vector simply picks out the corresponding coordinate of $\mathbf k$, therefore the distance to the nearest face is found by dividing half the edge length by the coordinate of $\mathbf k$ with the greatest absolute value.

If you can’t assume that the cube is ever in the convenient “home” position above, you can still use (*) but you’ll have to compute three face normals from the data at hand. You don’t need to resort to cross products to do this, though: Pick any vertex. The direction vectors of the three edges that meet at that vertex give you the required face normals. These vectors are just the differences of the coordinates of the chosen vertex and the coordinates of its three neighbors. Since the vectors are all the same length, you can avoid normalizing until you’ve selected the one that minimizes the magnitude of $t$ (multiplying unit normals by the same nonzero scalar doesn’t affect the relative magnitudes of their dot products with $\mathbf k$). Also, since you’re only interested in the magnitudes of these dot products, you can be fairly cavalier about whether you use inward or outward normals. In other words, the order of the points when you subtract coordinates doesn’t make any difference.