# How to find the point of a plane where vector crosses cube wall?

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 $$$$

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.

• Do you know the rotation angle? – amd May 29 at 18:43
• Yes I do. If rotation speed is 510 like in the video, then 1 frame is 1/510. In 510 frames the shape will rotate fully. – Tomasm21 May 29 at 20:45

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.

• But how n⋅x=s/2? I don't understand it. I need proof or demonstration. The only thing I saw is that n⋅x = 0 : mathonline.wikidot.com/point-normal-form-of-a-plane – Tomasm21 Jun 3 at 16:38
• @Tomasm21 Look up how to compute the distance between a point and a plane, or, better yet, work it out for yourself using the geometric meaning of the dot product, This is pretty basic stuff. – amd Jun 3 at 16:47
• Come, check my latest thoughts in edit from 2019-06-09 – Tomasm21 Jun 9 at 16:57

Don't know why you went on discussing about the length of the segment vector, $$R$$ etc.
You just need a vector parallel to the axis of rotation, of whichever length, but better if unitary, like the one you give in spherical coordinates.

Then you do not need (necessarily) to find the intersection of the axis with cube.
Just follow this related post .

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.

Thank you amd. You were right. It was enough to compute only three face normals for three planes bounded by three cube edges. Each of the edge has 1 same top vertex while the other vertexs is on the rest closest intersecting planes ends. If the rotation axis vector points to one of the other three planes then parameter $$t$$ is negative. And the correct one which suits to my cube is the most little number module. When the &t& number is integer then the

Cube image

The free point that should belong to some plane is defined like this:

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

Other point which is important to the plane equation is the main point $$P_3(x_3, y_3, z_3)$$ from which planes face normals direct:

$$|n|=\small\sqrt{(x_3-x_1)^2+(y_3-y_1)^2+(z_3-z_1)^2}=\large s, \\ \large \vec{n_1}= \bigg(\frac{x_3-x_1}{s}, \frac{y_3-y_1}{s}, \frac{z_3-z_1}{s}\bigg)=(a_1,b_1,c_1),\\ \large \vec{n_2}= \bigg(\frac{x_3-x_4}{s}, \frac{y_3-y_4}{s}, \frac{z_3-z_4}{s}\bigg)=(a_2,b_2,c_2),\\ \large \vec{n_3}= \bigg(\frac{x_3-x_7}{s}, \frac{y_3-y_7}{s}, \frac{z_3-z_7}{s}\bigg)=(a_3,b_3,c_3).$$

Three plane equations for three cube walls:

$$a_1(x-x_3)+b_1(y-y_3)+c_1(z-z_3)=0,\\ a_2(x-x_3)+b_2(y-y_3)+c_2(z-z_3)=0,\\ a_3(x-x_3)+b_3(y-y_3)+c_3(z-z_3)=0.$$

We have to insert rotation vector expressions with the parameter $$$$ to the free point location to all three planes and count parameter $$t$$:

$$a_1(x_rt_1-x_3)+b_1(y_rt_1-y_3)+c_1(z_rt_1-z_3)=0,\\ \Large t_1=\frac{-(a_1x_3+b_1y_3+c_1z_3)}{a_1x_r+b_1y_r+c_1z_r}\normalsize,\\ a_2(x_rt_2-x_3)+b_2(y_rt_2-y_3)+c_2(z_rt_2-z_3)=0,\\ \Large t_2=\frac{-(a_2x_3+b_2y_3+c_2z_3)}{a_2x_r+b_2y_r+c_2z_r}\normalsize,\\ a_3(x_rt_3-x_3)+b_3(y_rt_3-y_3)+c_3(z_rt_3-z_3)=0,\\ \Large t_3=\frac{-(a_3x_3+b_3y_3+c_3z_3)}{a_3x_r+b_3y_r+c_3z_r}\normalsize,\\$$

We have three parameter values but only the most little in module is the answer. Negative ones mean that the vector cross the opposite planes and not the one we took to calculate. When we have the right parameter then we multiply it by Rotation vector equations and get the coordinate where exactly rotation vector crosses cube wall.

The video how it looks is this: Right Cube rotation axis
The code for coordinate count and axis draw is this: The code