summaryrefslogtreecommitdiff
path: root/src/haversine/libs/listing_065.cpp
diff options
context:
space:
mode:
authorRaymaekers Luca <luca@spacehb.net>2025-11-13 01:06:18 +0100
committerRaymaekers Luca <luca@spacehb.net>2025-11-13 01:06:18 +0100
commitce38d72eb8d607a30d332a85c837834bffb0b8fd (patch)
treeff80ef18d49007981650ff1916900f1232be6fb5 /src/haversine/libs/listing_065.cpp
parent7c2d674835f78c3af9b4f7c1d75f29b6b5a10f6e (diff)
checkpoint
Diffstat (limited to 'src/haversine/libs/listing_065.cpp')
-rw-r--r--src/haversine/libs/listing_065.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/haversine/libs/listing_065.cpp b/src/haversine/libs/listing_065.cpp
new file mode 100644
index 0000000..86e087c
--- /dev/null
+++ b/src/haversine/libs/listing_065.cpp
@@ -0,0 +1,39 @@
+#include <math.h>
+
+static f64 Square(f64 A)
+{
+ f64 Result = (A*A);
+ return Result;
+}
+
+static f64 RadiansFromDegrees(f64 Degrees)
+{
+ f64 Result = 0.01745329251994329577 * Degrees;
+ return Result;
+}
+
+// NOTE(casey): EarthRadius is generally expected to be 6372.8
+static f64 ReferenceHaversine(f64 X0, f64 Y0, f64 X1, f64 Y1, f64 EarthRadius)
+{
+ /* NOTE(casey): This is not meant to be a "good" way to calculate the Haversine distance.
+ Instead, it attempts to follow, as closely as possible, the formula used in the real-world
+ question on which these homework exercises are loosely based.
+ */
+
+ f64 lat1 = Y0;
+ f64 lat2 = Y1;
+ f64 lon1 = X0;
+ f64 lon2 = X1;
+
+ f64 dLat = RadiansFromDegrees(lat2 - lat1);
+ f64 dLon = RadiansFromDegrees(lon2 - lon1);
+ lat1 = RadiansFromDegrees(lat1);
+ lat2 = RadiansFromDegrees(lat2);
+
+ f64 a = Square(sin(dLat/2.0)) + cos(lat1)*cos(lat2)*Square(sin(dLon/2));
+ f64 c = 2.0*asin(sqrt(a));
+
+ f64 Result = EarthRadius * c;
+
+ return Result;
+}