Intersection of ray with circle in 3D subject to endpoint and orientation constrains Imagine a circle of radius R in 3D space with a line l running threw it's center C in a direction perpendicular to the plane of the circle. Basically, like the axel of a wheel. 
From a given point P that is not on the circle or on l, a ray extends to intersect both l and the circle. What would be the equations used to find the intersection points the ray make with the circle and l? You are given the coordinates of C and P, the radius R and the orientation of l.
I am trying to model looking from a point P onto a wheel-axis shape and find from point of view P the point of the edge of the circle that would appear to intersect with it's axis. Of course it doesn't but it is how this 3d structure would appear in a 2d image if a camera was situated at point P.
 A: No need to rotate anything, it is a matter of very simple geometry, which if you follow through, gives you a very simple explicit algorithm for computing the points you need. 
Assume the orientation of the lines $l$ is given by a vector $\vec{v}$. Then the circle, call it $k$, has given center $C$ and radius $r$ and lies in the plane $\beta$ passing through $C$ and orthogonal to $\vec{v}$. Denote by $s$ the ray through point $P$ that intersects both line $l$ and the circle $s$. Then, since $s$ intersects $l$, the two together determines a plane $\alpha$, which is orthogonal to the plane of the circle $\beta$ and is transverse to the circle itself. The ray $s$ lies in this plane $\alpha$ and at the same time intersects $k$ so the ray $s$ passes through the point of intersection of $k$ and $\alpha$. So all you have to do is find the intersection points of the plane $\alpha$ and the circle $k$ (technically, you have two solutions of your problem). It becomes even simpler when you notice that the planes $\alpha$ and $\beta$ (the one of the circle $k$) intersect at a common line $l_C$ that passes thorough the circle center $C$, that is $l_C = \alpha \cap \beta$. Therefore the intersection points between $k$ and $\alpha$ are in fact the intersection points of $l_C$ and $k$. In other words, the two points you are looking for are exactly $l_C \cap k$. Which, by the way, are the two points on $l_C$ at a distance $r$ from point $C \in l_C$ (on either side of $C$ on $l_C$).    
All of the above observations prompt the following algorithm:


*

*If the dot product $\big(\vec{v} \cdot \vec{CP}\big) < 0$ then set $\vec{v} := -\vec{v}$. This way we make sure both vectors $\vec{v}$ and $\vec{CP}$ are in the same half space with respect to the plane $\beta$ defined by the circle (recall $\beta$ is orthogonal to $\vec{v}$).

*Define vector $$\vec{n} = \vec{v} \times \vec{CP}$$ (cross product) which is orthogonal to $\alpha$, and thus orthogonal to $l_C$.

*Then define vector $$\vec{w} = \vec{v} \times \vec{n} = \vec{v} \times\big(\vec{v} \times \vec{CP}\big)$$ and normalize it to $$\vec{u} = \frac{\vec{w}}{|\vec{w}|} = \frac{ \vec{v} \times\big(\vec{v} \times \vec{CP}\big)}{| \vec{v} \times\big(\vec{v} \times \vec{CP}\big)|}$$ Vector $\vec{u}$ is parallel to line $l_C$ because $l_C$ is orthogonal to both vectors $\vec{v}$ and $\vec{n}$, and vector $\vec{u}$ is also orthogonal to both of them (cross product of the two).

*If point $O$ is the origin of the coordinate system, a point $X$ lies on the line $l_C$ if and only if
$$\vec{OX}= \vec{OC} + t \, \vec{u}$$ 

*The two intersection points $Q_1$ and $Q_2$ you are looking for are 
$$\vec{OQ_1}= \vec{OC} + r \, \vec{u}$$
$$\vec{OQ_2}= \vec{OC} - r \, \vec{u}$$
If I am not wrong, according to the way I have deliberately defined the relative location of the vectors, point $Q_1$ should be "behind" the line $l$ and point $Q_2$ "in front" when looking from point $P$. For further reference I will use the notations $R_1 = PQ_1 \cap l$ and $R_2 = PQ_2 \cap l$.


*For $i=1,2$ calculate the vectors $$\vec{Q_iP} =   \vec{CP} - (-1)^{i} \, r \, \vec{u}  \,\,\, \text{ and } \,\,\, |Q_iP| = \sqrt{\big(\vec{Q_iP} \cdot \vec{Q_iP} \big)}$$ i.e. the latter is a dot product and then square root. The former equality holds because $$\vec{Q_iP} =  \vec{OP} - \vec{OQ_i} = \vec{CP} - \vec{CQ_i} = \vec{CP} - (-1)^i \, r \, \vec{u}$$

*For $i=1,2$ calculate $\cos(\alpha_i) = \cos\big( \angle \, CQ_iP\big)$ by calculating the dot products $$\cos(\alpha_i) = (-1)^i\,  \frac{\big(\, \vec{u} \cdot\vec{Q_iP} \,\big)}{|{Q_iP}|}$$ 

*For $i=1,2$ calculate $$\vec{OR_i} = \vec{OQ_i} + \left(\,\,\frac{r}{|Q_iP| \,\cos(\alpha_i)}\,\right) \, \vec{Q_iP}$$ where by construction $R_1$ is in between $Q_1$ and $P$ (i.e. $Q_1$ is behind the line $l$ when looking from point $P$) while $Q_2$ is outside the straight segment formed by  $Q_2$ and $P$.
If you manage to write a computer implementation of this algorithm, let me know if it works or not. If not, I will look up what needs to be corrected.
A:           


Rotate everything so that the disk lies in the $xy$-plane with its center at the origin, and the line $L$ coincides with the $z$-axis. One more rotation about the $z$-azis places
$p$ to project onto the $x$-axis. Now it is easy to connect $p$ through $L$ to the circle. Then reverse all rotations.
A: You should have simply stated your question in terms of orthographic projection from the get go. Try the following algorithm, I hope it works (if, of course, I understand correctly what your goal is).
This time you assume you are given the vector $\vec{p}$ instead of the point $P$ that determines the direction of all rays  illuminating the circle. Last time, all rays were emanating from the point $P$. This time, all rays are parallel to $\vec{p}$. Everything else, including the notations, stays the same. The theoretical arguments are almost word for word the same, except this time the ray $s$ does not pass through point $P$ but is parallel to $\vec{p}$ instead.
The algorithm is a bit simpler this time, depending what points you really need to find. I will find all of them: $Q_1, Q_2, R_1, R_2$ but you can choose which ones you really need.


*

*Calculate $$\cos(\theta) = \frac{\big( \vec{v} \cdot \vec{p}\big)}{|\vec{v}||\vec{p}|}$$ where $\theta = \angle\,(\vec{v},\vec{p})$ is angle between first vector $\vec{v}$ and second vector $\vec{p}$, following that order. 

*If $\cos(\theta) < 0 $ then set $$\vec{v} := -\vec{v}$$ $$\cos(\theta) := - \cos(\theta)$$ Else, keep $\vec{v}$ and $\cos(\theta)$ the same. This way  $\vec{v}$ and  $\vec{p}$ are in the same half-space with respect to the plane $\beta$ determined by the circle (and so $\beta$ is orthogonal to $\vec{v}$).
Observe that since $Q_1R_1$ is parallel to $\vec{p}$
$$\angle \, Q_1R_1C = \angle (\vec{v}, \vec{p}) = \theta$$


*Calculate $$\vec{u} = \frac{ \vec{v} \times \big(\vec{v}\times\vec{p} \big)}{|\vec{v} \times \big(\vec{v}\times\vec{p}\big)|}$$ This vector is calculated so that it points from $C$ to $Q_1$ which is the point behind $l$.

*Calculate $$\vec{CQ_1} = r \vec{u} \,\,\, \text{ and } \,\,\, 
\vec{CQ_2} = - r \vec{u}$$ which leads to $$\vec{OQ_1} =\vec{OC} +  r \vec{u} \,\,\, \text{ and } \,\,\, 
\vec{OQ_2} = \vec{OC} - r \vec{u}$$
If you look at triangle $CQ_1R_1$, you will see that it is right-angled triangle with angle $\angle \, Q_1R_1C = \theta$ and $|CQ_1| = r$ so $$|CQ_1| = r \, \cot(\theta) =  \frac{r \,\cos(\theta)}{\sqrt{1 - \cos^2(\theta)}}$$ Thus


*Calculate 
$$\vec{CR_1} =  \frac{r \,\cos(\theta)}{\sqrt{1 - \cos^2(\theta)}} \, \frac{\vec{v}}{|\vec{v}|}\,\,\,\,\, \text{ and } \,\,\,\,\, \vec{CR_2} = - \,  \frac{r \,\cos(\theta)}{\sqrt{1 - \cos^2(\theta)}} \, \frac{\vec{v}}{|\vec{v}|}$$ which lead to
$$\vec{OR_1} = \vec{OC} + \frac{r \,\cos(\theta)}{\sqrt{1 - \cos^2(\theta)}} \, \frac{\vec{v}}{|\vec{v}|}\,\,\,\,\, \text{ and } \,\,\,\,\, \vec{OR_2} =  \vec{OC} - \,  \frac{r \,\cos(\theta)}{\sqrt{1 - \cos^2(\theta)}} \, \frac{\vec{v}}{|\vec{v}|}$$ 

