mirror of
https://github.com/sdr-enthusiasts/docker-adsb-ultrafeeder.git
synced 2024-11-23 22:30:09 +00:00
add local version of distance.c
This commit is contained in:
parent
4ac8c1aa2f
commit
9a99ca9118
2 changed files with 71 additions and 5 deletions
|
@ -2,13 +2,10 @@ FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base AS build
|
||||||
|
|
||||||
RUN set -x && \
|
RUN set -x && \
|
||||||
apt-get update -y && \
|
apt-get update -y && \
|
||||||
apt-get install -q -o Dpkg::Options::="--force-confnew" -y --no-install-recommends \
|
apt-get install -q -o Dpkg::Options::="--force-confnew" -y \
|
||||||
git gcc && \
|
git gcc && \
|
||||||
cd / && \
|
cd / && \
|
||||||
git clone --depth=1 --single-branch https://github.com/sdr-enthusiasts/docker-vesselalert.git && \
|
curl -sSL https://raw.githubusercontent.com/sdr-enthusiasts/docker-adsb-ultrafeeder/main/downloads/distance.c -o /distance.c && \
|
||||||
cd /docker-vesselalert/src && \
|
|
||||||
# make the output in meters instead of nautical miles:
|
|
||||||
sed -i 's|/ 1852.0||g' distance.c && \
|
|
||||||
gcc -static distance.c -o distance -lm -Ofast
|
gcc -static distance.c -o distance -lm -Ofast
|
||||||
|
|
||||||
FROM ghcr.io/sdr-enthusiasts/docker-tar1090:latest
|
FROM ghcr.io/sdr-enthusiasts/docker-tar1090:latest
|
||||||
|
|
69
downloads/distance.c
Normal file
69
downloads/distance.c
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
---------------------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2002-2022, Chris Veness
|
||||||
|
Adaptations Copyright (C) 2023, John Norrbin (JohnEx)
|
||||||
|
Adaptations (C) 2023, Ramon F. Kolb (kx1t)
|
||||||
|
|
||||||
|
MIT License:
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without
|
||||||
|
restriction, including without limitation the rights to use,
|
||||||
|
copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
sell copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||||
|
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
---------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#define PI 3.14159265
|
||||||
|
|
||||||
|
// https://www.movable-type.co.uk/scripts/latlong.html
|
||||||
|
double distance(double lat_a, double lon_a, double lat_b, double lon_b)
|
||||||
|
{
|
||||||
|
|
||||||
|
double lat_a_scaled = lat_a * (double)PI / 180.0;
|
||||||
|
double lat_b_scaled = lat_b * (double)PI / 180.0;
|
||||||
|
double lat_delta = (lat_b - lat_a) * (double)PI / 180.0;
|
||||||
|
double lon_delta = (lon_b - lon_a) * (double)PI / 180.0;
|
||||||
|
|
||||||
|
double a = sin(lat_delta / 2.0) * sin(lat_delta / 2.0) + cos(lat_a_scaled) * cos(lat_b_scaled) * sin(lon_delta / 2.0) * sin(lon_delta / 2.0);
|
||||||
|
double c = 2.0 * atan2(sqrt(a), sqrt(1.0 - a));
|
||||||
|
|
||||||
|
return 6372797.56085 * c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if (argc != 5)
|
||||||
|
{
|
||||||
|
printf("Usage: distance lat1 lon1 lat2 lon2\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double lat1 = atof(argv[1]);
|
||||||
|
double lon1 = atof(argv[2]);
|
||||||
|
double lat2 = atof(argv[3]);
|
||||||
|
double lon2 = atof(argv[4]);
|
||||||
|
|
||||||
|
double d = distance(lat1, lon1, lat2, lon2);
|
||||||
|
printf("%f\n", d);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue