1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Is there a formula to calculate the following?

Discussion in 'Tools programming' started by Vector, 17/1/07.

  1. Vector

    Vector

    Joined:
    30/11/06
    Messages:
    69
    Country:
    us-pennsylvania
    Having longitude and latitude and then adding distance (kilometers) and coming up with new values for longitude and latitude.:banghead:
  2. scruffyduck

    scruffyduck Administrator Staff Member FSDevConf team Resource contributor

    Joined:
    17/9/05
    Messages:
    25,480
    Country:
    wales
    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

    Vector

    Joined:
    30/11/06
    Messages:
    69
    Country:
    us-pennsylvania
    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

    Manuel Ambulo

    Joined:
    29/9/06
    Messages:
    162
    Country:
    panama
    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

    Vector

    Joined:
    30/11/06
    Messages:
    69
    Country:
    us-pennsylvania
    Could still use more help with this calculation.
  6. Siggy

    Siggy

    Joined:
    12/6/04
    Messages:
    66
    Country:
    australia
    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

    Vector

    Joined:
    30/11/06
    Messages:
    69
    Country:
    us-pennsylvania
    Thanks Siggy!
  8. Vector

    Vector

    Joined:
    30/11/06
    Messages:
    69
    Country:
    us-pennsylvania
    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

    lmoelleb

    Joined:
    23/4/05
    Messages:
    266
    You are aware the .NET Math library use radians, not degrees?
  10. Vector

    Vector

    Joined:
    30/11/06
    Messages:
    69
    Country:
    us-pennsylvania
    Yes I do !
  11. ziporama

    ziporama

    Joined:
    28/9/06
    Messages:
    203
    Country:
    unitedstates
    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

    Vector

    Joined:
    30/11/06
    Messages:
    69
    Country:
    us-pennsylvania
    How do you write the following code in VB.Net?

    What language is used in the following expression?
    Your expression is "lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi"

    VB.Net expression is "?"

    Helloooooo ??!!
    Last edited: 4/2/07

Share This Page