-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsphere.cpp
47 lines (40 loc) · 1.12 KB
/
sphere.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "HamClock.h"
/* solve a spherical triangle:
* A
* / \
* / \
* c / \ b
* / \
* / \
* B ____________ C
* a
*
* given A, b, c find B and a in range -PI..B..PI and 0..a..PI, respectively..
* cap and Bp may be NULL if not interested in either one.
* N.B. we pass in cos(c) and sin(c) because in many problems one of the sides
* remains constant for many values of A and b.
*/
void solveSphere (float A, float b, float cc, float sc, float *cap, float *Bp)
{
float cb = cosf(b), sb = sinf(b);
float sA, cA = cosf(A);
float x, y;
float ca;
float B;
ca = cb*cc + sb*sc*cA;
if (ca > 1.0F) ca = 1.0F;
if (ca < -1.0F) ca = -1.0F;
if (cap)
*cap = ca;
if (!Bp)
return;
if (sc < 1e-7F)
B = cc < 0 ? A : M_PIF-A;
else {
sA = sinf(A);
y = sA*sb*sc;
x = cb - ca*cc;
B = y ? (x ? atan2f(y,x) : (y>0 ? M_PI_2F : -M_PI_2F)) : (x>=0 ? 0 : M_PIF);
}
*Bp = B;
}