/src/PROJ/src/conversions/geoc.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * Project: PROJ.4 |
3 | | * Purpose: Conversion from geographic to geocentric latitude and back. |
4 | | * Author: Thomas Knudsen (2017) |
5 | | * |
6 | | ****************************************************************************** |
7 | | * Copyright (c) 2017, SDFE, http://www.sdfe.dk |
8 | | * Copyright (c) 2017, Thomas Knudsen |
9 | | * |
10 | | * Permission is hereby granted, free of charge, to any person obtaining a |
11 | | * copy of this software and associated documentation files (the "Software"), |
12 | | * to deal in the Software without restriction, including without limitation |
13 | | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
14 | | * and/or sell copies of the Software, and to permit persons to whom the |
15 | | * Software is furnished to do so, subject to the following conditions: |
16 | | * |
17 | | * The above copyright notice and this permission notice shall be included |
18 | | * in all copies or substantial portions of the Software. |
19 | | * |
20 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
21 | | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
22 | | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
23 | | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
24 | | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
25 | | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
26 | | * DEALINGS IN THE SOFTWARE. |
27 | | *****************************************************************************/ |
28 | | |
29 | | #include <math.h> |
30 | | |
31 | | #include "proj.h" |
32 | | #include "proj_internal.h" |
33 | | |
34 | | PROJ_HEAD(geoc, "Geocentric Latitude"); |
35 | | |
36 | | /*************************************************************************************/ |
37 | | PJ_COORD pj_geocentric_latitude(const PJ *P, PJ_DIRECTION direction, |
38 | 0 | PJ_COORD coord) { |
39 | | /************************************************************************************** |
40 | | Convert geographical latitude to geocentric (or the other way round if |
41 | | direction = PJ_INV) |
42 | | |
43 | | The conversion involves a call to the tangent function, which goes |
44 | | through the roof at the poles, so very close (the last centimeter) to the |
45 | | poles no conversion takes place and the input latitude is copied directly to |
46 | | the output. |
47 | | |
48 | | Fortunately, the geocentric latitude converges to the geographical at |
49 | | the poles, so the difference is negligible. |
50 | | |
51 | | For the spherical case, the geographical latitude equals the geocentric, |
52 | | and consequently, the input is copied directly to the output. |
53 | | **************************************************************************************/ |
54 | 0 | const double limit = M_HALFPI - 1e-9; |
55 | 0 | PJ_COORD res = coord; |
56 | 0 | if ((coord.lp.phi > limit) || (coord.lp.phi < -limit) || (P->es == 0)) |
57 | 0 | return res; |
58 | 0 | if (direction == PJ_FWD) |
59 | 0 | res.lp.phi = atan(P->one_es * tan(coord.lp.phi)); |
60 | 0 | else |
61 | 0 | res.lp.phi = atan(P->rone_es * tan(coord.lp.phi)); |
62 | |
|
63 | 0 | return res; |
64 | 0 | } |
65 | | |
66 | | /* Geographical to geocentric */ |
67 | 0 | static void forward(PJ_COORD &coo, PJ *P) { |
68 | 0 | coo = pj_geocentric_latitude(P, PJ_FWD, coo); |
69 | 0 | } |
70 | | |
71 | | /* Geocentric to geographical */ |
72 | 0 | static void inverse(PJ_COORD &coo, PJ *P) { |
73 | 0 | coo = pj_geocentric_latitude(P, PJ_INV, coo); |
74 | 0 | } |
75 | | |
76 | 17 | static PJ *PJ_CONVERSION(geoc, 1) { |
77 | 17 | P->inv4d = inverse; |
78 | 17 | P->fwd4d = forward; |
79 | | |
80 | 17 | P->left = PJ_IO_UNITS_RADIANS; |
81 | 17 | P->right = PJ_IO_UNITS_RADIANS; |
82 | | |
83 | 17 | P->is_latlong = 1; |
84 | 17 | return P; |
85 | 17 | } |