Arc intersection on a sphere Background: my JavaScript library https://github.com/mistic100/Photo-Sphere-Viewer allows to create 2D polygons overlaying a spherical photo. Polygons are defined by a serie a longitude/latitude points. Spherical coordinates are then projected on the camera near frustrum. This works for small polygons but not for big ones when points are behind the camera.
Long story short: I would like to compute intermediary points on the circle delimiting the "front half-sphere" (the one rendered by the camera).

The question:

GeoGebra source file
We have :


*

*a red sphere centered on 0,0,0 of radius 1

*a black circle of radius 1 and always centered on 0,0,0. So this circle can be any big circle of the sphere.

*An blue arc BD on the sphere surface (here there are 3 arcs but the question is only for one). The arc is only known by its points B and D, only the shortest arc between these points is interesting.


Want I need : the coordinates of point H, intersection of arc BD and the black circle.
I only have basic trigonometry knowledge (I forgot almost all my math courses !) and I can't get my head of this and find where to start...
Thank you

Each great circle on a sphere centered at the origin corresponds to a unique plane through the origin; the intersection of two great circle arcs can be computed using the corresponding planes and linear algebra.
The procedure below assumes $B$ and $D$ do not lie on a diameter of the sphere (i.e., are distinct and not antipodal).
Synopsis: Convert $B$ and $D$ to Cartesian coordinates, and let $N$ be a (non-zero) normal vector to the plane of the black circle. If
$$
n = \frac{B \times D}{\|B \times D\|},\qquad
v = n \times B,
$$
then
$$
H = \frac{-(N \cdot v)B + (N \cdot B)v}{\|-(N \cdot v)B + (N \cdot B)v\|}.
$$
(This gives Cartesian coordinates, of course, which may need to be converted back to spherical, the details of which depend on your conventions for spherical coordinates.)

Details: Convert the spherical coordinates of $B$ and $D$ to Cartesian spatial coordinates using your favorite convention. For example, if $\theta$ denotes longitude (with the positive $x$-axis on the prime meridian) and $\phi$ latitude, then
$$
(x, y, z) = (\cos\theta \cos\phi, \sin\theta \cos\phi, \sin\phi),\qquad
-\pi < \theta \leq \pi,\ -\pi/2 \leq \phi \leq \pi/2.
\tag{1}
$$
The normalized cross product
$$
n = \frac{B \times D}{\|B \times D\|}
$$
is orthogonal to the plane $P$ containing the spherical arc $BD$. (In the preceding formula, $B$ and $D$ denote Cartesian coordinate vectors obtained from (1).) The unit vector
$$
v = n \times B
$$
lies in $P$, is orthogonal to $B$, and "points toward $D$" in the following sense: Every point of the spherical arc through $B$ and $D$ has the form
$$
B \cos t + v \sin t
\tag{2}
$$
for some $t$ with $0 < t \leq \arccos(B \cdot D) < \pi$.
The point $H$ you seek is the unique point of the form (2) lying in the plane $P'$ of your black circle. To find this point, let $N$ denote a non-zero normal vector of $P'$; the point (2) lies in $P'$ if and only if
$$
0 = N \cdot (B \cos t + v \sin t)
  = (N \cdot B) \cos t + (N \cdot v) \sin t.
\tag{3}
$$
A bit of algebra (rearranging (3) and substituting into (2)) gives
$$
H = \frac{-(N \cdot v)B + (N \cdot B)v}{\|-(N \cdot v)B + (N \cdot B)v\|}.
$$
