Reputation: 431
i am trying to calculate the distance between two points and using the acos()
function in process...but i am not getting a precise result..in case the distance is small
float distance_between(dest& point1,dest point2) {
float EARTH_RADIUS = 6371.0;//in km
float point1_lat_in_radians = point1.lat*(PI/180);
float point2_lat_in_radians = point2.lat*(PI/180);
float point1_long_in_radians = point1.lon*(PI/180);
float point2_long_in_radians = point2.lon*(PI/180);
float res = acos( sin( point1_lat_in_radians ) * sin( point2_lat_in_radians ) + cos( point1_lat_in_radians ) * cos( point2_lat_in_radians ) * cos( point2_long_in_radians - point1_long_in_radians) ) * EARTH_RADIUS;
cout<<res<<endl;
res = round(res*100)/100;
return res;
}
i am checking the distance between the following co-ordinates
52.378281 4.900070 and 52.379141 4.880590
52.373634 4.890289 and 52.379141 4.880590
the result is 0 in both cases..i know the distance is small but is there a way to get precise distance like 0.xxx?
Upvotes: 2
Views: 1780
Reputation: 73434
Use double
instead of float
to get more precision.
That way you are going to use this prototype:
double acos (double x);
A must read is the Difference between float and double question. From there we have:
Upvotes: 3