feat: midpoint calculator
This commit is contained in:
23
geographical-centre/midpoint.jq
Normal file
23
geographical-centre/midpoint.jq
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
def pi: 3.14159265;
|
||||||
|
def radians: (. * pi) / 180;
|
||||||
|
def unradians: (. * 180) / pi;
|
||||||
|
|
||||||
|
def cartesian: (.latitude | radians) as $lat | (.longitude | radians) as $lon | {
|
||||||
|
x: (($lat | cos) * ($lon | cos)),
|
||||||
|
y: (($lat | cos) * ($lon | sin)),
|
||||||
|
z: ($lat | sin)
|
||||||
|
};
|
||||||
|
|
||||||
|
def average: add / length;
|
||||||
|
|
||||||
|
map(cartesian)
|
||||||
|
| {
|
||||||
|
x: map(.x) | average,
|
||||||
|
y: map(.y) | average,
|
||||||
|
z: map(.z) | average
|
||||||
|
}
|
||||||
|
| ((.x * .x + .y * .y) | sqrt) as $hypotenuse
|
||||||
|
| {
|
||||||
|
longitude: atan2(.y; .x) | unradians,
|
||||||
|
latitude: atan2(.z; $hypotenuse) | unradians
|
||||||
|
}
|
||||||
18
geographical-centre/points.json
Normal file
18
geographical-centre/points.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"latitude": 50.0935111,
|
||||||
|
"longitude": 8.7616557
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"latitude": 51.3546268,
|
||||||
|
"longitude": 12.4096159
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"latitude": 52.4616859,
|
||||||
|
"longitude": 13.3781642
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"latitude": 49.4854674,
|
||||||
|
"longitude": 8.537643
|
||||||
|
}
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user