text: Intersection of a line with a spherical cap
  
  Given a reference frame $x,y,z$, and a sphere of radius $R$ with center in the origin of the frame, I take a spherical cap with height $h$ having the center on the $x$ axis. I am looking for a formula giving the intersection angle between a line starting from $x_0,y_0,z_0$ of direction cosines $\alpha,\beta,\gamma$ and the cap vs. $y$ and $z$ or in alternative, in spherical coordinates vs. $\theta$ and $\phi$. Can anybody help me? Thanks.
  
  • Have you got the target angle in Cartesian coordinates before, then? – mrs Jul 10 '13 at 18:00
  • @BabakS.I have only the direction cosines of the line, but I don't know the target angle of the line respect to the plane tangent to the spherical cap in the intersection point. – Riccardo.Alestra Jul 11 '13 at 8:21
  • I see what you are looking for. My question here is that you wanna that in spherical coordinate and this may make the result a bit harder, I think. Right? – mrs Jul 11 '13 at 8:23
  • @BabakS:In cartesian coordinates is OK if this is simpler than in spherical ones – Riccardo.Alestra Jul 11 '13 at 8:40
  
  Start by computing the intersections of the line with the entire sphere, if any. You have $$\mathbf p_0 = (x_0,y_0,z_0)$$ and $$\mathbf v=(\alpha,\beta,\gamma)$$, so this is simply a matter of solving the quadratic equation $$\|\mathbf p_0+t\mathbf v\|^2=R$$ for $$t$$. Discard any solutions for which $$x\notin[R-h,R]$$. If you also need the intersection with the “bottom” of the cap, solve $$x_0+t\alpha=R-h$$ for $$t$$ and check that the distance of the resulting point from the origin is $$\le R$$.