aboutsummaryrefslogblamecommitdiffstats
path: root/libtellurian_gaussian_radius_radians.c
blob: 7b14ed5257cf911b373bd5cec05a14b79dc182e8 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                                                         
            






                                                     


                                        
                                           


                                               





































                                                               
/* 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(geodetic(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