1 /* 2 * Copyright (c) 2021 Kevin Townsend 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <math.h> 8 #include <errno.h> 9 #include <zsl/zsl.h> 10 #include <zsl/orientation/orientation.h> 11 zsl_grav_lat_alt(zsl_real_t lat,zsl_real_t alt,zsl_real_t * g)12int zsl_grav_lat_alt(zsl_real_t lat, zsl_real_t alt, zsl_real_t *g) 13 { 14 if (alt < 0.0 || lat > 90.0 || lat < -90.0) { 15 *g = NAN; 16 return -EINVAL; 17 } 18 19 zsl_real_t d_to_r = ZSL_PI / 180.0; 20 21 *g = 9.780318 * (1.0 + 0.0053024 * ZSL_SIN(lat * d_to_r) * 22 ZSL_SIN(lat * d_to_r) - 0.0000058 * ZSL_SIN(2.0 * lat * d_to_r) * 23 ZSL_SIN(2.0 * lat * d_to_r)) - 0.000003085 * alt; 24 25 return 0; 26 } 27