Click here to Skip to main content
15,914,074 members
Home / Discussions / C#
   

C#

 
AnswerRe: Beaten and defeated by this simple geography compass problem. [modified] Pin
Luc Pattyn12-Jan-09 16:08
sitebuilderLuc Pattyn12-Jan-09 16:08 
GeneralRe: Beaten and defeated by this simple geography compass problem. Pin
PIEBALDconsult12-Jan-09 16:15
mvePIEBALDconsult12-Jan-09 16:15 
AnswerRe: Beaten and defeated by this simple geography compass problem. Pin
Luc Pattyn12-Jan-09 16:25
sitebuilderLuc Pattyn12-Jan-09 16:25 
GeneralRe: Beaten and defeated by this simple geography compass problem. Pin
PIEBALDconsult12-Jan-09 19:47
mvePIEBALDconsult12-Jan-09 19:47 
AnswerRe: Beaten and defeated by this simple geography compass problem. Pin
Luc Pattyn13-Jan-09 2:27
sitebuilderLuc Pattyn13-Jan-09 2:27 
GeneralRe: Beaten and defeated by this simple geography compass problem. Pin
Garry Freemyer12-Jan-09 16:16
Garry Freemyer12-Jan-09 16:16 
AnswerRe: Beaten and defeated by this simple geography compass problem. [modified] Pin
Luc Pattyn12-Jan-09 16:32
sitebuilderLuc Pattyn12-Jan-09 16:32 
GeneralI keep getting zero as the angle no matter what. [modified] Pin
Garry Freemyer13-Jan-09 6:04
Garry Freemyer13-Jan-09 6:04 
That site you included is the first one I tried but the function below that is modeled after the formula there always returns zero no matter what I do when passed in the values. Since I do not understand the formula I cannot understand why it's not working.


Input values are as follows ....

double lat1 = degreesToRadian(ParadiseLat);
double lon1 = degreesToRadian(ParadiseLon);
double lat2 = degreesToRadian(SanDiegoLat);
double lon2 = degreesToRadian(SanDiegoLon);

double degreesToRadian(double x)
{
return (M_PI * (x) / 180.);
}

double radianToDegrees(double x)
{
return x * 57.2957795;
}

The function below always returns zero no matter when I expect it to be returning something close to south south west, absolutely not north east. Expected at least something more than 220 degrees, certainly not 44 degrees. I noticed that it appeared to be a mirror image of what I wanted, but I don't know how to fix it.

I know some are wondering why I don't understand this "Simple High School Trig", and the answer is I never got to take Trigonometry. The reason for that is a tale of Gross Misdiagnosis and Gross Negligence by school officials and Medical personal. Its a drama I prefer not to get into here.

Someone said San Diego was South East of Paradise CA .. well maybe so but when I looked at the map it looked South West.

*You will note that the return value is truncated to an integer in the final step just before the modulus % operator. This is because when I try this with anything but an integer, be it signed or unsigned, I get a compiler error. Apparently % only works for whole numbers.

int latitudeLongitudeLocationsToAngleOfTravelInDegrees(double latRad1, double lonRad1, double latRad2, double lonRad2)
{
//double theRadians = atan2(cos(latRad1)*sin(latRad2)-sin(latRad1)*cos(latRad2)*cos(lonRad2-lonRad1), sin(lonRad2-lonRad1)*cos(latRad2));
//double theDegreesInRad = radianToDegrees(theRadians);
//theDegreesInRad = (theDegreesInRad * PI / 180) + 360;
//int theDegrees = radianToDegrees(theDegreesInRad);
//theDegrees = theDegrees % 360;
double theAngleInRad = atan2(cos(latRad1)*sin(latRad2)-sin(latRad1)*cos(latRad2)*cos(lonRad2-lonRad1), sin(lonRad2-lonRad1)*cos(latRad2));
int theDegrees = radianToDegrees(theAngleInRad); // *See comment above.
return (theDegrees + 360) / 360;
// return theDegrees;
}

Been there, done that, forgot why!

modified on Tuesday, January 13, 2009 12:10 PM

AnswerRe: I keep getting zero as the angle no matter what. [modified] Pin
Luc Pattyn13-Jan-09 6:37
sitebuilderLuc Pattyn13-Jan-09 6:37 
GeneralRe: I keep getting zero as the angle no matter what. Pin
Garry Freemyer13-Jan-09 7:12
Garry Freemyer13-Jan-09 7:12 
AnswerRe: I keep getting zero as the angle no matter what. [modified] Pin
Luc Pattyn13-Jan-09 8:14
sitebuilderLuc Pattyn13-Jan-09 8:14 
GeneralRe: I keep getting zero as the angle no matter what. Pin
Garry Freemyer13-Jan-09 14:04
Garry Freemyer13-Jan-09 14:04 
GeneralRe: I keep getting zero as the angle no matter what. Pin
Garry Freemyer13-Jan-09 14:06
Garry Freemyer13-Jan-09 14:06 
AnswerRe: Beaten and defeated by this simple geography compass problem. Pin
PIEBALDconsult12-Jan-09 16:12
mvePIEBALDconsult12-Jan-09 16:12 
GeneralRe: Beaten and defeated by this simple geography compass problem. Pin
Garry Freemyer12-Jan-09 16:22
Garry Freemyer12-Jan-09 16:22 
GeneralRe: Beaten and defeated by this simple geography compass problem. Pin
Jason Lepack (LeppyR64)12-Jan-09 16:47
Jason Lepack (LeppyR64)12-Jan-09 16:47 
GeneralRe: Beaten and defeated by this simple geography compass problem. Pin
PIEBALDconsult12-Jan-09 19:49
mvePIEBALDconsult12-Jan-09 19:49 
AnswerRe: Beaten and defeated by this simple geography compass problem. Pin
J4amieC12-Jan-09 22:19
J4amieC12-Jan-09 22:19 
AnswerRe: Beaten and defeated by this simple geography compass problem. Pin
Alan Balkany13-Jan-09 4:28
Alan Balkany13-Jan-09 4:28 
AnswerRe: Beaten and defeated by this simple geography compass problem. Pin
Luc Pattyn14-Jan-09 3:24
sitebuilderLuc Pattyn14-Jan-09 3:24 
GeneralRe: Beaten and defeated by this simple geography compass problem. Pin
Garry Freemyer14-Jan-09 9:43
Garry Freemyer14-Jan-09 9:43 
AnswerRe: Beaten and defeated by this simple geography compass problem. [modified] Pin
Luc Pattyn14-Jan-09 9:51
sitebuilderLuc Pattyn14-Jan-09 9:51 
GeneralRe: Beaten and defeated by this simple geography compass problem. Pin
Garry Freemyer14-Jan-09 10:28
Garry Freemyer14-Jan-09 10:28 
AnswerRe: Beaten and defeated by this simple geography compass problem. [modified] Pin
Luc Pattyn14-Jan-09 10:40
sitebuilderLuc Pattyn14-Jan-09 10:40 
GeneralRe: Beaten and defeated by this simple geography compass problem. Pin
Garry Freemyer14-Jan-09 11:05
Garry Freemyer14-Jan-09 11:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.