Algorithm for finding orientation of each face on a polyhedron?

495 Views Asked by At

I am working on making a dice rolling application and I need to find out how far in each of the three dimensions I must rotate each of the dice to make the correct side face the camera so the user can see what the result of each roll was. I can easily do this with two dimensional figures, but three dimensional polyhedrons seem to be much more difficult. I guess I am just going about it the wrong way, but here is what I thought I could do.

I know the center of each of the dice will always be (0, 0, 0), so I thought I could just find the centroid of each face and project a line through it. The line would be about 2.0 units in length. I was thinking of forming a triangle with that line and a line from the camera to the center of the die as well, then I could use simple trigonometry to find the angles that I need. My problem with this method is that, while it works with 90º angles, I need the angles before the calculations in order to find the length of the hypotenuse. Obviously, if I had those angles I could skip this all together.

So, that leaves me with no ideas. I do not have any idea what to do here, so I would like to request your help. So, is there any way to find the number of degrees a line must be rotated to become parallel to another line?

1

There are 1 best solutions below

2
On BEST ANSWER

is there any way to find the number of degrees a line must be rotated to become parallel to another line?

Given 2 straight lines in $\Bbb R^3$, one can define the angle between them as the angle between their vector directions (or its complement to $\pi$ if bigger than $\pi/2$).

More precisely, if you have two vectors $v_1=(x_1,y_1,z_1)$ and $v_2=(x_2,y_2,z_2)$ with angle between them $0\le\phi = \arccos\frac{(v_1,v_2)}{|v_1| |v_2|}\le\pi$, then the angle $0 \le \alpha\le\pi/2$ between the corresponding lines is defined as $\phi$ if $\phi\le\pi/2$ and $\pi-\phi$ if $\phi>\pi/2$.

This angle $\alpha$ is the angle you have to rotate by one of the line to make parallel to the other one.

The axis of rotation is perpendicular to both vectors $v_1$ and $v_2$ and, thus, parallel to their cross-product $v_1\times v_2$; unless, of course, the lines are parallel, in which case the cross-product and the angle are zero and no rotation is necessary.