Consider the spherical triangle shown in Figure 1 to write,
cos x = sin fM * sin fP + cos fM * cos fP * cos(lM - fP) (1)By dividing Eq. (2) by (3) we obtain,
sin A = sin (lM - lP ) * cos fM / sin x (2)
cos A = (sin fM - cos x * sin fP) / (sin x * cos fP) (3)
tan A= sin(lM-lP)* cos fP* cos fM/ (sin fM-cos x * sin fP)By substituting Eq. (1) for cos x, finally, we get as direction angle of Qibla,
tan A = sin ( lM - lP) / { cos fP * tan fM - sin fP * cos ( lM - lP) } (4)Where; fP - Latitude of a position, lP - Longitude of a position fM - Latitude of Mecca, lM - Longitude of Mecca
A = the direction angle (Azimuth) of Qibla - from North to East
Grate Circle: Three points define a plane as seen in Fig. 2. Where L is the Location, M is the position of Mecca and C is the Center of the Earth. Imagine that this plane cutting through the surface of the Earth which generates a circle. This circle is called a Grate Circle which is the shortest distance/direction between two point on Earth. The shortest part of a circle is the direction/distance. Equation 4 is based on this definition.