Click here to Skip to main content
15,920,508 members
Home / Discussions / C#
   

C#

 
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 
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 
Good catch. I can't believe I keep replacing the % with /.

I did the changes, and when I fed in longitude and latitude for Paradise CA to Colorado Springs Colorado, I got a wildly unexpected result.

Given the code fragments below the angle I was expecting was something like 57 degrees came back and said it was 1 degree! NORTH!!

I get the formula working for Paradise CA to Colorado Springs and it breaks down when I try for a Destination of San Diego, and if I fix San Diego, it breaks for Colorado Springs. I might as well be passing these figures into the random function. I would scream but you are trying to help me and it would not be polite.

...

#define ParadiseLat 39.743
#define ParadiseLon -121.605

#define SanDiegoLat 32.723
#define SanDiegoLon -117.165

#define ColoSpringsLat 38.835
#define ColoSpringsLon -104.823

...

double lat1 = degreesToRadian(ParadiseLat);
double lon1 = degreesToRadian(ParadiseLon);

double lat2 = degreesToRadian(ColoSpringsLat);
double lon2 = degreesToRadian(ColoSpringsLon);

....

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

...

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);
return (theDegrees + 360) % 360;
// return theDegrees;
}

Been there, done that, forgot why!

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 
AnswerRe: Beaten and defeated by this simple geography compass problem. [modified] Pin
Luc Pattyn14-Jan-09 11:03
sitebuilderLuc Pattyn14-Jan-09 11:03 
GeneralRe: Beaten and defeated by this simple geography compass problem. Pin
Garry Freemyer14-Jan-09 11:16
Garry Freemyer14-Jan-09 11:16 

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.