-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsphere.cpp
More file actions
40 lines (33 loc) · 947 Bytes
/
sphere.cpp
File metadata and controls
40 lines (33 loc) · 947 Bytes
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
/* a few handy spherical trig functions.
*/
#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);
float sb = sinf(b);
float cA = cosf(A);
float ca = CLAMPF (cb*cc + sb*sc*cA, -1, 1);
if (cap)
*cap = ca;
if (Bp) {
float sA = sinf(A);
float y = sA*sb*sc;
float x = cb - ca*cc;
*Bp = atan2f (y,x);
}
}