How to compute unit direction vector of a ray in 3D given its origin and angle with XZ and YZ planes?

1.2k Views Asked by At

I want to compute the unit direction vector for a ray in 3D. I have the coordinates of the starting point of the ray and angle the ray makes with the XZ and YZ plans where X is rightward, Y is upward and Z is forward direction. Any idea how should I go about it?

1

There are 1 best solutions below

0
On

Now that's a strange way to proceed. If I'm not mistaken, your basis isn't right-handed. If you have a choice in the matter, I'd recommend switching to something more conventional.


Say your unit direction vector is $\mathbf u=\left(x,y,z\right)^t$. The unit normal vector to plane $XZ$ has coordinates $\mathbf j=\left(0,1,0\right)^t$. Let $\alpha_j$ be the angle between $\mathbf u$ and the $XZ$ plane. Then $$ \langle \mathbf u,\ \mathbf j \rangle = y = \cos\left(\frac\pi 2-\alpha_j\right) $$ Repeat for the other angle with plane $YZ$, you obtain $x$. You can deduce $z$ from the constraint that it is a unit vector.