Jump to content
The simFlight Network Forums

Offset for flown distance


Erikk
 Share

Recommended Posts

Hi Erik,

 

There isn't one.  You're program needs to track this during the flight.  At regular intervals you need to calculate the distance between the current position and the previous position and add this to a total distance variable.

 

The DLL can handle the trigonometry for you if you use the FsLatLonPoint class.  This takes in an FsLongitude and FsLatitude to specify a position on the Earth.  You can use one of the DistanceFrom...() methods to calculate the distance between two positions.

 

The FsLongitude and FsLatitude classes take in the raw 8-byte value from the fsuipc offset so you don't need to worry about converting this to degrees.

 

For more details and examples, see the UserGuide.pdf:

"Reading and Displaying Longitudes and Latitudes" on Page 15 and
"Distances and Bearings between Two Points" on Page 17

 

Paul

Link to comment
Share on other sites

Hi,

 

Mm okay thank you. I took a look at the manual and the distance between you and EGLL. That's works for me. But what I want is the position from that you start FS. So in the DIM where you write down the coordinates from egll. It should be the coordinates of your starting location. But I have no idea how to get that. 

Link to comment
Share on other sites

Hi Erik,

 

There are no offsets to tell you the starting location.  In any case the distance between the starting point and the current aircraft location isn't really going to be the distance flown because not many routes are in a straight line.

 

You'll need to have a button in your application which the the user presses when they are at the starting location. When this button is pressed you read the current position of the aircraft and store it in a variable as the 'previous location'.

 

Then at regular intervals you get the current position again, work out the distance from the 'previous location' and add it to the total distance flown.  Then you copy the current location into the 'previous location' ready for the next time.

 

The more frequently you sample the position the more accurate your total distance will be, and the more frequently you can update your display of the distance so far.  I would suggest once every 30 seconds would be good enough but you could make it more or less frequent according to your preferences.  You should add another timer to your form to do this calculation at your chosen interval.

 

Paul

Link to comment
Share on other sites

Erik,

 

Don't know what language you are programming in but here is what I wrote for my app in vb.net.

You can modify this into whatever language you are using. The maths is there but you will need to change the objects/vars to match your app

    Sub GetTotalDistanceFlown()

        'calculate total distance flown so far'
        Static firstrun As Boolean = True

        If firstrun = True Then
            'remember position for next run otherwise distance starts with lat/lon of 0 and gives 6000nm at KSEA!'
            PreviousLat = ApplicationObjects.objAircraft.CurrentLatitude
            PreviousLon = ApplicationObjects.objAircraft.CurrentLongitude
            firstrun = False
        Else
            'convert longitude into radians'
            CurrentLat = Calculations.Deg2Rad(ApplicationObjects.objAircraft.CurrentLatitude)
            CurrentLon = Calculations.Deg2Rad(ApplicationObjects.objAircraft.CurrentLongitude)

            'as total distance is in nm convert to rad before calculating new distance'
            ReportGlobal.TotalDistanceFlownNM = Calculations.nm2Rad(ReportGlobal.TotalDistanceFlownNM)
            ReportGlobal.TotalDistanceFlownNM = ReportGlobal.TotalDistanceFlownNM + (2 * Math.Asin(Math.Sqrt((Math.Sin((PreviousLat - CurrentLat) / 2)) ^ 2 + Math.Cos(PreviousLat) * Math.Cos(CurrentLat) * (Math.Sin((PreviousLon - CurrentLon) / 2) ^ 2))))
            ReportGlobal.TotalDistanceFlownNM = Calculations.Rad2nm(ReportGlobal.TotalDistanceFlownNM)
            ReportGlobal.TotalDistanceFlownNM = Math.Round(ReportGlobal.TotalDistanceFlownNM, 4)
            '4 decimal places for accuracy on chart x axis'

            PreviousLat = ApplicationObjects.objAircraft.CurrentLatitude
            PreviousLon = ApplicationObjects.objAircraft.CurrentLongitude
        End If

    End Sub

required function for above

    Shared Function Rad2nm(ByVal Rad)
        'This function converts radians to nm'
        Rad2nm = Rad * ((180 * 60) / Math.PI)
        Return Rad2nm
    End Function

    Shared Function nm2Rad(ByVal nm)
        'This function converts radians to nm'
        nm2Rad = nm * Math.PI / (180 * 60)
        Return nm2Rad
    End Function
Link to comment
Share on other sites

Oke, thank you both for your help. I am making it in VB.net.  BUt what do you mean with ApplicationObjects?  And for Previous lat and lon I have add this

 

Dim PreviousLat As FsLatitude = New FsLatitude(Latitude.Value)

Dim PreviousLon As FsLongitude = New FsLongitude(Longitude.Value)

And should I make another dim.... for the CurrentLat and lon with the same value of lat and lon?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.