![]() |
|
#1
|
|||
|
|||
Help me write this formula in c++Hello!
I'm creating a program that calculates the distance between two cities. I have problems with converting the formula to c++ code. Here is the formula Code:
Here, d is the distance between the towns, a1 and a2 are their latitudes,b1 and b2 are their longitudes, and R is the radius of the earth. The latitudes and longitudes are given in degrees but sin and cos functions work with radians. I've been trying to make this two days and it doesn't work Here is what I've done CPP / C++ / C Code:
and also CPP / C++ / C Code:
but both methods did not work. Can you please tell me what I'm doing wrong? Any help will be appreciated. p.s. Sorry for my English. I'm still learning |
|||
|
#2
|
|||
|
|||
Re: Help me write this formula in c++Quote:
|
|
#3
|
|||
|
|||
Re: Help me write this formula in c++Quote:
Sorry for the mistake |
|
#4
|
|||
|
|||
Re: Help me write this formula in c++Quote:
Without validating your formula and without looking very closely at your "simplifications," I would say that, for one thing, I am almost sure that you have not interpreted the following notation correctly: Code:
I believe that this should be taken to designate arcsin(xxx), not 1.0/sin(xxx). The standard library function asin() calculates the arcsin in radians. Regards, Dave Footnote: I have always used the "haversine" formula (look it up on wikipedia or wherever...) Code:
Code:
If you convert your latitude and longitude into radians before plugging into the formula, it might look a little cleaner: CPP / C++ / C Code:
|
|
#5
|
|||
|
|||
Re: Help me write this formula in c++Quote:
|
|
#6
|
|||
|
|||
Re: Help me write this formula in c++Quote:
So, beginning with the following assumptions:
Code:
CPP / C++ / C Code:
|
Recent GIDBlog
Not selected for officer school by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| Starting in the business? Time to write a Business Plan ! | WEBDOMAIN.com | Web Hosting Forum | 2 | 01-Aug-2006 04:12 |
| which language ? | onauc | C++ Forum | 2 | 19-Nov-2004 02:53 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 10:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The