- #1
DeepSeaBiscuit
- 3
- 0
Hello, I have the haversine function within my C++ program to calculate the distance between to points, the two tester points I have chosen are Swansea and Cardiff both located in Wales.
Swansea lat = 51.622559, long = -3.934534
Cardiff lat = 51.475661, long = -3.174688
The problem I am having is that the actual line distance for these two points is 55.02 km but my program keeps giving out 28.30 km and I am not sure why?
My function that I am using to calculate the distance is #include <cmath>
using namespace std;
double calcDistance(double lat2, double lat1, double long2, double long1)
{
double toRadians = 3.1415 / 180;
double dLat = (lat1-lat2)*toRadians;
double dLong = (long1-long2)*toRadians;
double a = pow(sin(dLat / 2), 2) + cos(lat1)*cos(lat2)*pow(sin(dLong/ 2),2);
double c = 2 * atan2(sqrt(a), sqrt(1-a));
double R = 6371;
double distance = R * c;
return distance;
}
Any help?
Swansea lat = 51.622559, long = -3.934534
Cardiff lat = 51.475661, long = -3.174688
The problem I am having is that the actual line distance for these two points is 55.02 km but my program keeps giving out 28.30 km and I am not sure why?
My function that I am using to calculate the distance is #include <cmath>
using namespace std;
double calcDistance(double lat2, double lat1, double long2, double long1)
{
double toRadians = 3.1415 / 180;
double dLat = (lat1-lat2)*toRadians;
double dLong = (long1-long2)*toRadians;
double a = pow(sin(dLat / 2), 2) + cos(lat1)*cos(lat2)*pow(sin(dLong/ 2),2);
double c = 2 * atan2(sqrt(a), sqrt(1-a));
double R = 6371;
double distance = R * c;
return distance;
}
Any help?