- #1
perplexabot
Gold Member
- 329
- 5
Hello all. So i am trying to calculate the distance between two points on the Earth's surface. Here is what I have:
Where tarList and startLoc are the two locations.
Also, the program takes user input in the form of:
LATITUDEVALUE/(NorS) LONGITUDEVALUE(WorE) NAME
e.g: 2341/N 41355/W Random City
I have a part of the code that changes the sign of the latitude or longitude according to (N or S and W or E), here it is:
I am not getting errors but I am not achieving correct answers. Does anyone know what the problem may be? Thank you physics forums as usual!
Code:
//calculate distance here
dlat = abs(startLoc.lat - tarList[i].lat);
dlon = abs(startLoc.lon - tarList[i].lon);
a = pow(sin(dlat/2),2) + ( cos(startLoc.lat)*cos(tarList[i].lat)*pow(sin(dlon/2),2) );
c = 2*atan2(sqrt(a),sqrt(1-a));
tarList[i].distance = R * c;
Also, the program takes user input in the form of:
LATITUDEVALUE/(NorS) LONGITUDEVALUE(WorE) NAME
e.g: 2341/N 41355/W Random City
I have a part of the code that changes the sign of the latitude or longitude according to (N or S and W or E), here it is:
Code:
//adjust sign of latitude according to N/S
if(tarList[i].noSo == 'N'){
tarList[i].lat = getLat(aString);
}else{
tarList[i].lat = -getLat(aString);
cout<<"MINUS USED!"<<endl;
}
//adjust sign of longitude according to W/E
if(tarList[i].weEa == 'E'){
tarList[i].lon = getLon(aString);
}else{
tarList[i].lon = -getLon(aString);
cout<<"MINUS USED!"<<endl;
}
I am not getting errors but I am not achieving correct answers. Does anyone know what the problem may be? Thank you physics forums as usual!