aboutsummaryrefslogtreecommitdiffstats
path: root/libtellurian_gaussian_radius_radians.c
blob: 02d05863e33728f24c9ee05f24b807c1440c4afb (plain) (blame)
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
47
48
49
50
51
52
53
54
55
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


double
libtellurian_gaussian_radius_radians(double latitude)
{
	double a = LIBTELLURIAN_EQUATORIAL_RADIUS;
	double b = LIBTELLURIAN_POLAR_RADIUS;
	double c = b / a;
	double neg_e2 = fma(c, c, -1.0);
	double neg_e2_plus_1 = c * c;
	double s = sin(latitude);
	double denom = fma(neg_e2, s * s, 1.0);
	return a * sqrt(neg_e2_plus_1) / denom;
}


#else


static int
check(double lat)
{
	double g = libtellurian_gaussian_radius_radians(lat);
	double m = libtellurian_meridian_radius_radians(lat);
	double n = libtellurian_transverse_radius_radians(lat);
	double e = sqrt(m * n);
	double err = fabs((g - e) / e);
	return err <= 1.0e-8;
}

int
main(void)
{
	ASSERT(check(0));
	ASSERT(check(D30));
	ASSERT(check(D45));
	ASSERT(check(D60));
	ASSERT(check(D90));
	ASSERT(check(D180));
	ASSERT(check(-D30));
	ASSERT(check(-D45));
	ASSERT(check(-D60));
	ASSERT(check(-D90));
	ASSERT(check(-D180));
	ASSERT(check(1.0));
	ASSERT(check(2.0));
	ASSERT(check(3.0));
	return 0;
}


#endif