Background
Countless generations of children have wondered where they would end up if they dug a hole directly downwards. It turns out that this would, unsurprisingly, be rather dangerous, but anyway...
Antipodes are points that are directly opposite each other on the Earth's surface. This means that if a line was drawn between the two points, it would pass through the centre of the Earth.
Challenge
Write a program or function that, given a point, finds its antipode.
In this challenge, points are represented using the longitude-latitude system and degrees, arc minutes and arc seconds. To find the antipode, swap the directions of each ordinate (N <-> S and W <-> E) and subtract the longitude ordinate from 180 degrees.
Example:
Take the point N 50 26 23 W 4 18 29. Swap the directions to give S 50 26 23 E 4 18 29. Subtract the longitude ordinate from 180 0 0 to give 175 41 31, leaving the antipode coordinates as S 50 26 23 E 175 41 31.
Rules
Input
A set of latitude-longitude coordinates, in any reasonable format, where each ordinate contains a direction, a number of degrees, a number of arc minutes, and a number of arc seconds.
Output
The latitude-longitude coordinates of the antipode, in any reasonable format, where each ordinate contains a direction, a number of degrees, a number of arc minutes, and a number of arc seconds.
Take reasonable to mean that each part of the coordinate can be distinguished unambiguously.
Specs
- The direction for the latitude ordinate is
NorS, and that for the longitude ordinate isWorE. - All coordinate values are integers. The degree value will be between
0and90for latitude, and between0and180for longitude. The arc minute and arc second values for both ordinates will be between0and59. - If all the values for an ordinate are
0, either direction is acceptable. - There is no need to zero-pad any values.
- No latitude ordinate will ever be larger than
90degrees, and no longitude ordinate will ever be larger than180degrees. - Standard loopholes apply.
Test cases
N 50 26 23 W 4 18 29 -> S 50 26 23 E 175 41 31
S 43 9 9 E 0 0 5 -> N 43 9 9 W 179 59 55
N 0 0 0 E 0 0 0 -> S/N 0 0 0 W/E 180 0 0 (either direction fine in each case)
S 1 2 3 W 4 5 6 -> N 1 2 3 E 175 54 54
S 9 21 43 W 150 7 59 -> N 9 21 43 E 29 52 1
S 27 40 2 W 23 0 0 -> N 27 40 2 E 157 0 0
N 0 58 37 W 37 0 0 -> S 0 58 37 E 143 0 0
Useful links
This is code-golf, so the shortest answer in bytes wins!
N,S,E, orWas a direction, while the redundant0introduces ambiguity as to which value represents which component of the ordinate. \$\endgroup\$