# Is there a formula to calculate the following?

Discussion in 'Tools programming' started by Vector, 17 Jan 2007.

1. ### Vector

Joined:
30 Nov 2006
Messages:
69
Country:
Having longitude and latitude and then adding distance (kilometers) and coming up with new values for longitude and latitude.

2. ### scruffyduckAdministratorStaff MemberFSDevConf teamResource contributor

Joined:
17 Sep 2005
Messages:
28,993
Country:
Yes there is but you need bearing as well as distance to generate terminal co-ordinates. I do not have the code here with me now but if you do a Google search for spherical geometry you will probably find what you want. I think that is how I found the information originally

3. ### Vector

Joined:
30 Nov 2006
Messages:
69
Country:
Bearing yes.

I am not a Mathematician and I can't find exactly what I need so if you come across the formula some day please post or email it to me. I would be very greatful.

4. ### Manuel Ambulo

Joined:
29 Sep 2006
Messages:
173
Country:
I recommend you to check this website:

http://williams.best.vwh.net/avform.htm

Have most usefull aviations formulaes, including the one you are looking for....hope this helps..

Best Regards,

Manuel Ambulo

5. ### Vector

Joined:
30 Nov 2006
Messages:
69
Country:
Could still use more help with this calculation.

6. ### Siggy

Joined:
12 Jun 2004
Messages:
66
Country:
Here is an exmaple:

The following is a bit rough, and it is based on the earth being a globe I believe:

Let's start at lat1=45 deg, lon1=0 deg and add 2km, bearing 30 deg (=tc):

d = (2km / (2 * pi * 6378km) * 360 deg) = 0.01797 deg
(The 2 * pi * 6378km is the circumference of the earth approx.)

lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))

lat = asin(sin(45 deg) * cos(0.01797 deg) + cos(45 deg) * sin(0.01797 deg) * cos(30 deg))
= asin(0.70729880824) = 45.015561771 deg

lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi

lon = mod(0 deg - asin(sin(30 deg) * sin(0.01797 deg) / cos(45.015561771 deg) * 360 deg / (2 * pi)) + 180 deg, 360 deg) - 180 deg =
= mod(0 deg - asin(0.0002218341622887) + 180 deg, 360 deg) - 180 deg
= mod(-0.0127101613552102486 + 180, 360) deg - 180 deg =
= -0.0127101613552102486 deg

Then keep in mind that some people who live at 'negative' longitudes do not like that fact and modify formulas so their longitudes have positive values. So the new longitude is actually 0.0127101613552102486 deg east (positive).

7. ### Vector

Joined:
30 Nov 2006
Messages:
69
Country:
Thanks Siggy!

8. ### Vector

Joined:
30 Nov 2006
Messages:
69
Country:
Well my brain-cloud must be acting up again. lolol
I can't get these two calculations to work in VB.Net correctly.

1. lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))

You show 'lat=45.015561771' as a result.
When using this statement in VB.Net I get 'lat=1.020217787680854'.

2. lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi

Your explanation of calculating lon is showing 360 and 180 degree values which are not shown in the above calculation.

The 'd = (2km / (2 * pi * 6378km) * 360 deg)' calculation for the new distance value is ok!

If you could explain a little more I would appreciate it.
Thanks.

9. ### lmoelleb

Joined:
23 Apr 2005
Messages:
268
Country:
You are aware the .NET Math library use radians, not degrees?

Joined:
30 Nov 2006
Messages:
69
Country:
Yes I do !

11. ### ziporama

Joined:
28 Sep 2006
Messages:
203
Country:
Could you post your code - that would greatly help Vector.

Classic computation problems include mixing precision or data types, so I would make sure all your variables are doubles, and that your radians are indeed radians and not degrees (as mentioned above).

Regards,

Etienne

12. ### Vector

Joined:
30 Nov 2006
Messages:
69
Country:
How do you write the following code in VB.Net?

What language is used in the following expression?