### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Problems with time and Distance Help Please  (Read 4648 times)

#### TRon

• Hero Member
• Posts: 536
##### Re: Problems with time and Distance Help Please
« Reply #60 on: July 07, 2020, 09:02:59 pm »
Thanks, I'll Work the code up in a demo to see if it matches what I now have.
NP, and please take your time to see how I did things. In case of question then feel free to ask.

Quote
But I can't trust the results. This is on the flight from KMEK to KPHX.
Yours or mine ?

I have no idea why you wouldn't be able to trust the results (whether they be mine or yours, unless we are still making an error somewhere)

Quote
I'm departing at 15:23:30 and arriving at 16:44:03. It's about an hour and 16 difference.
An hour and 16 difference between two different timezones. Look at my time-table for that flight, specifically at the UTC times. That is the real duration of the flight (well, theoretically).

Quote
But then there is 2 hours difference between KMEK and KPHX. So then I'm wondering.
Again take a closer look at my timetable if you will.

Code: [Select]
` Location   ICAO        UTC                     Local                   UTC+  DST+ Departure  KMKE        2020-06-19 20:49:09     2020-06-19 15:49:09     -360    60    Flight  B787        2020-06-19 23:44:03     -                          0     0   Arrival  KPHX        2020-06-19 23:44:08     2020-06-19 16:44:08     -420     0`UTC offset for KMKE = -360 min (= -6 hours)
UTC offset for KPHX = -420 min (= -7 hours)

But.... KMKE also has daylight saving active. so:
UTC offset + DST offset for KMKE = -360 + 60 = -300 mins (= -5 hours)
UTC offset + DST offset for KPHX = -420 +  0 = -420 mins (= -7 hours)

Which accounts for the 2 hour (virtual) time-difference between these two different timezones.

So, when UTC is 17:00 then that means it is 12 o'clock (local time) at/in KMKE and 10 o'clock (local time) at/in KPHX.

Would you fly an hour from 12:00 to 13:00 (based on timezone PHX) then the time in/at KPHX would be 11:00.

I have no idea what I could say in addition to that, in order to make things easier to understand. That is how time and timezones work.

That is why I calculate everything absolute to UTC, and only in the end convert those values back to local timezone (including DST). All times in the timetable which you can find at the column UTC actually makes sense in relation to the flight and other data. The local times however don't make any sense and can make your head explode
(timezones/offsets are but a mere virtual/imaginary construct, and imho serves no purpose whatsoever other than screw with my internal clock for instance each and every time DST is (de-)activated).

My aim with the table was that you would be able to see everything with a single overview of all mentioned items. You should focus there on the UTC times, as they are the real true absolute date-time values.

Other than that, I had a quick view at the meaning of the words departure and arrival as used in aviation.

If you take a closer look at PHX arrival time, in relation to the Flight Time then you can see it is only a small distance/time-diff between them (1.2 km, about 5 seconds based on cruise speed). However, even though i have no idea what ADS records includes exactly, it would imho not be strange to assume that the last 5 seconds is not being flown at cruise-speed, rather it is the taxi from the run-way to the terminal. That would explain why it wouldn't be 'fair' to still add the 'waste'-time of descending, taxing etc to that arrival time (the plane is already busy 'performing' that 'waste' sequence). On the other hand you would have to account for that at the departure location, and would explain the difference between the/my theoretical calculation and actual flight information.

For the second test (Kansai - Amsterdam) you can see that, because of the ADS record that was taken mid-flight (and not at beginning/end), when you add additional 'waste'-time for departure and arrival the/my calculated times seems to make more or less sense in relation to the actual flight data.

Quote
That's the only time I get is a Lat/Lon and a Unix/GMT but I suspect the time is actually UTC.
tbh it was my first thought

If it wasn't then how would these ADS records look like for a 15 hour flight going through several different timezones ? Should you then use each lat/lon to determine the timezone, then calculate the absolute time to then calculate it back to local a timezone if you wish to work with the data from those records (for whatever purpose) ?

Imagine you have an airport located at the border of a timezone, the airport is busy and the plane circles around in its queue until it is it's turn to actually initiate landing sequence. Each and every time the plane circles around through different time zones. How would those ADS records look like if the epoch field was actually expressed in "local" time ? Pretty messy if you ask me

#### winni

• Hero Member
• Posts: 1899
##### Re: Problems with time and Distance Help Please
« Reply #61 on: July 07, 2020, 10:19:58 pm »

Quote
That's the only time I get is a Lat/Lon and a Unix/GMT but I suspect the time is actually UTC.
tbh it was my first thought

Hi!

I get lost among all those different datas - please give again the data of the flight Japan-Amsterdam plus the tempory Lat/Long and time of the airplane.

* What does the documentation say about the epoch time stamp of the airplane ?????

Winni

#### TRon

• Hero Member
• Posts: 536
##### Re: Problems with time and Distance Help Please
« Reply #62 on: July 07, 2020, 10:51:01 pm »
I get lost among all those different datas - please give again the data of the flight Japan-Amsterdam plus the tempory Lat/Long and time of the airplane.
I needed to construct that myself:
Code: [Select]
`opr Dept Arrv Plane EPOCH time Lat     Lon    CallSign??? RJBB EHAM B77W  1592610832 63.62   38.28  ????`It seems to be this flight: https://www.klm.de/flight-status/flight-details?date=20200620&originAirportCode=KIX&destinationAirportCode=AMS&flightNumber=KL0868

And I was able to collect the following information from that:
Code: [Select]
`Departure    ICAO : RJBB    name : Kansai International Airport lat,lon : 34.42729900,135.24400300Arrival    ICAO : EHAM    name : Amsterdam Airport Schiphol lat,lon : 52.30860100,4.76389000Flight    ICAO : B77W    name : ??? ?????? lat,lon : 63.62000000,38.28000000`The rest of my data are calculations based on that information. Feel free to retrieve your own to verify my airport data.

PS @JLWest: also feel free to post the UK flight RDA record, I get lost in your form-data

#### winni

• Hero Member
• Posts: 1899
##### Re: Problems with time and Distance Help Please
« Reply #63 on: July 07, 2020, 11:19:51 pm »
Thanks for the data.

If I put it all together I think the epoch time of the airplane  is UTC:

The Lat/Long of 63.62000000,38.28000000 is 100 km west of Archangelsk, Russia.
The epoch timestamp is 23:53 h

0:30 RJBB 20.06.2020  +9  UTC = 15:30
Archangelsk                          UTC = 23:53
5:30 EHAM 20.06.2020  +2  UTC = 03:30

The time  delta to Dep is  8:23 h, the delta to Arr is 3:37h

That is a relation of  69% : 31%, which seems to be quiet right if I look at the map.

Winni

#### TRon

• Hero Member
• Posts: 536
##### Re: Problems with time and Distance Help Please
« Reply #64 on: July 07, 2020, 11:42:48 pm »
Thank you for the verification @winni.

This is what I was able to calculate from the information:
Code: [Select]
`Timetable Location   ICAO        UTC                     Local                   UTC+  DST+ Departure  RJBB        2020-06-19 16:17:02     2020-06-20 01:17:02      540     0    Flight  B77W        2020-06-19 23:53:52     -                          0     0   Arrival  EHAM        2020-06-20 02:25:15     2020-06-20 04:25:15       60    60`
In that case, my calculations could work as a base which could be extended by (automatically) looking up the airport related data (location, lat/lon etc) from an external resource, as well as the airplane related information (cruise speed) and finally using a database in order to collect the timezone related information.

Then everything could be retrieved and calculated automatically from a single ADS record entry.

Which then would raise for me the question @JLWest, why you would want to do so ? e.g. would it not be easier to collect actual existing flight information and use that information for adding flights in your simulator ?

#### winni

• Hero Member
• Posts: 1899
##### Re: Problems with time and Distance Help Please
« Reply #65 on: July 08, 2020, 01:07:09 am »
Hi!

I don't want to spoil the party, but ......

For an intercontinental flight the airplanes take the route of the great cirle.  Ok - only a part of it which has a complicated name I forgot.

If you draw the great circle from Osaka to Amsterdam it will never ever touch 63.62,38.28
It goes much more north through the Kara Sea and Nowoja Semlja to get some radioaktivity from all the bomb tests. Then over the Barent Sea and then at the Atlanic side of Norway down to Amsterdam.

The only excuse is that there is no radar contact on the greatest part of the route.
So maybe they just compute just the current Lat and Long.
But the have not recognized that the earth is a ball.
Something like it ....

Winni

#### JLWest

• Hero Member
• Posts: 877
##### Re: Problems with time and Distance Help Please
« Reply #66 on: July 08, 2020, 01:21:50 am »
@TRon I have read the tables and data several times. It's impressive what you did.

I worked last night on the KMEK to KPHX route.
ICAO                 UTC                               Local                          UTC+  DST+
KMKE        2020-06-19 20:49:09     2020-06-19 15:49:09            -360    60
Arrival  KPHX        2020-06-19 23:44:08     2020-06-19 16:44:08  -420     0
========================================

KMEK                                                            15:23:30
KPHX                                                             16:44:03

The times are aa little different I think for 3 reasons. I'm using a different Haversine function than you. One supplied by Winni. My waste time is different and I haven''t figured out the speed you are using for either aircraft and we may be different there.

I can see the advantage of  staying in UTC time. I think it would be possible to to calculate these times if you had the following data points, which I do.

This is the data after parsing the XML record for a single flight. There are about 20 additional data points but nothing that I can use. Departure gate, arrival gate, IATA and IACO designations for everything. SWA is ICAO and IATA is WA doe SouthWest Airlines. A status of is landed and 0 is en-route.

SWA  B738  WN1747   N8574Z  1592610243  33.43330002  -111.9990005   KPHX  33.43427658  -112.0115814  -420   KMKE  42.94694519  -87.89705658  -300 status 1

"If it wasn't then how would these ADS records look like for a 15 hour flight going through several different timezones ? Should you then use each lat/lon to determine the timezone, then calculate the absolute time to then calculate it back to local a timezone if you wish to work with the data from those records (for whatever purpose) ?"

The ADS records would look like the one above regardless of it's position or time zone when transmitting. The data is collected and processed by the provided. He would get multiple transmissions from SWA  B738  WN1747 which is Southwest Airlines but he would only publish maybe one or two records. Maye an en-route and landed but usually one record.

ADS-B records contain altitude, heading, Speed in MACH I think but not all providers provide this. The provider I'm using doesn't. The fields come thru but they are almost always marked 'nul'. ADS data is pretty expensive.

"* What does the documentation say about the epoch time stamp of the airplane ?????" A note on that. There is a website that documents the ADS data. I went thru it and it's a little confusing.

I actually called the provide to ask about the time stamp. He said it was EPOCH/Unix GMT of the Lat/Lon position of the aircraft. He also stated it in an email. I looked and no longer have the email.

As for calculation in KM, meters I don't know anything about this scale. I would be glad to email my real name. You can look on the FAA website and check my pilot's lic. It is a Single engine, Commercial, Instrument rating with about 2,500 hours. The Gaiman 530, G1000, G750 and FMS are all done in miles and Flight Levels. Flight level FL350 is 35000 feet. I can and have programed all of those and I don't remember KM or meter in any. So that's why I did my calculations in miles.

An interesting thing about a U.S. pilots lic. It never expires, Once you have one it's good for life. It can be suspended for disciplinary reasons, but must have a time-frame with the suspension. You have to pass a physical every year to remain current. I failed my first physical 3 years ago and did not submit to the appeals board. I still have my lic. but it's not current.

FPC 3.2.0, Lazarus IDE v2.0.4
Windows 10 Pro 32-GB
Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

#### JLWest

• Hero Member
• Posts: 877
##### Re: Problems with time and Distance Help Please
« Reply #67 on: July 08, 2020, 01:32:54 am »
No the airplanes fly the Skyways not the great circle. There are actual highways in the shy and they vary by elevation and direction. Those are the routes commercial airlines fly. They are called names like J124 or Q111, There is one that is call I40 like Interstate 40 in the US. In a few years they will no longer be used as planes will only fly way-points and do GPS instrument landings. A way-point is a location in the sky, not on the ground and with the current civilian GPS capabilities it is within 1 to 3 meters. Military is within 18 inches - 2017 .

FPC 3.2.0, Lazarus IDE v2.0.4
Windows 10 Pro 32-GB
Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

#### winni

• Hero Member
• Posts: 1899
##### Re: Problems with time and Distance Help Please
« Reply #68 on: July 08, 2020, 01:42:21 am »
Hi!

So there are nearly no problems left.
The distance can be computed because we have lat and long of the departure and the destination.
It is easy to convert them to out of time dimensions like mile or ancient greek Daktylos.

We have the time zone of the lift off and the touch down. So we can compute the time zone difference.

And for now we should not care about the third dimension:

From Phoenix to Milwaukee it is about 2.000 kilometer.
An airplane o an intercontinental flight is 30.000 fett high, that is 10 kilometer.
So that is 0.5%. That deviation is beararble.

Winni

#### TRon

• Hero Member
• Posts: 536
##### Re: Problems with time and Distance Help Please
« Reply #69 on: July 08, 2020, 01:51:57 am »
I don't want to spoil the party, but ......
Yeah, i saw that flight as well.... very strange indeed. Perhaps they were unable to get clearance for that day (in time) ?

Instead, take the flight from Tuesday, Jul 07 00:30. There you can see it is flying almost in a straight line from Osaka to Bejing, over Mongolia, then stays pretty close to the Kazakstan border (at least in comparison to that flight you mentioned), then in a  bow towards Finland. Just across the Finnish border (close to Baltic sea) the plane flies more or less again in a straight line to Amsterdam.

#### winni

• Hero Member
• Posts: 1899
##### Re: Problems with time and Distance Help Please
« Reply #70 on: July 08, 2020, 01:55:55 am »
Hi!

European and Chinese systems now have a better resolution than GPS.

You try to tell me that flight companies waste fuel?
I don't believe that.

But back to the facts:
If the flight data being near Archagelsk were true you should have seen KLM868 coming in over the Balic Sea way to Amsterdam. Not seen there.

But - as you can see on flightradar24 - the KLM from Okasa is on the great circle and has first contact to the european continent with the north norwegian airports.

Winni

PS.: Just seen on flightradar24

« Last Edit: July 08, 2020, 01:59:28 am by winni »

#### winni

• Hero Member
• Posts: 1899
##### Re: Problems with time and Distance Help Please
« Reply #71 on: July 08, 2020, 02:17:04 am »
Hi!

In the attachment KLM 868 flight.
Screenshoot reduced to get below the 250 k restriction to bad quality.
I tried to discuss that problem but they are all stuck in the 80s.

No - that is not a great circle. No, no ...

Winni

#### TRon

• Hero Member
• Posts: 536
##### Re: Problems with time and Distance Help Please
« Reply #72 on: July 08, 2020, 02:49:50 am »
The times are aa little different I think for 3 reasons.
There is a difference indeed.

Quote
I'm using a different Haversine function than you. One supplied by Winni.
You can swap the haversine function with whatever works best for you. I got mine from Rosetta-code and is based on KM's (I live in a decimal country  )

Quote
My waste time is different
Correct, I have not accounted for waste time in my calculations/assumptions whatsoever. My code could easily be adapted for that though.

Quote
and I haven''t figured out the speed you are using for either aircraft and we may be different there.
Because I live in country where we work with the decimal system, everything I use is calculated in KiloMetre for distance and KiloMetre per hour for speed.

You can of course swap that out for mile and knot (or mile per hour) if you prefer.

Quote
I can see the advantage of  staying in UTC time.
If you would calculate with local times, e.g. needing to take into account the timezone offsets and DST's without using some sort of absolute reference, then you are for sure going to drive yourself insane

Because UTC is exactly meant to be used as an absolute measure point, then why not (ab)use it for the purpose it was invented for ? (the ADS record using UTC by EPOCH is there for a reason  )

Quote
There is a website that documents the ADS data. I went thru it and it's a little confusing.
Feel free to share in case its public accessible. So far, I was unable to locate any documentation with regards to those records (but I haven't had a good search for it yet either)

Quote
I actually called the provide to ask about the time stamp. He said it was EPOCH/Unix GMT of the Lat/Lon position of the aircraft. He also stated it in an email. I looked and no longer have the email.
Although I am far from knowledgeable on the subject, that sounds like rubbish.

That would really be unworkable if the data inside their database (ADS records) would contain an epoch timestamp based on the timezone/DST that corresponds to the lat/lon coordinates of that same ADS record.

Any data should be normalised before it can actually be used in a useful manner. If they won't do that for you, then it beats me why they ask such ridiculous prices for these datasets. (yes, i have been looking around, even for a simple (public knowledge) airport database and (public domain) timezone database they dare to trick you into a subscription service and bill you indefinitely with ridiculous amounts of number of request that you are allowed to perform per day/week/month).

Quote
I can and have programed all of those and I don't remember KM or meter in any. So that's why I did my calculations in miles.
No problem, it is all public knowledge. I do not know anything about knots and miles so had to look that up in order to calculate things in units that I am able to understand, so I guess that makes us even

In case you require help with that then feel free to ask. It is pretty easy to convert my code to work with knots and/or miles, although I personally do draw a line with measuring distances in inches.

1 Kilometre = 0.6213712 Mile, meaning 1 Mile = 1.609344 KiloMetre.

I used names for the conversions-constants inside my code and therefor should be self-explanatory ?

Quote
You have to pass a physical every year to remain current. I failed my first physical 3 years ago and did not submit to the appeals board. I still have my lic. but it's not current.
I'm sorry to hear that. I take it that is due to age related (health) issues ?

At least I do hope they won't expect you to run the 100 metres within 10 seconds in order for you to keep your license. I would have failed such a test myself ages ago

#### JLWest

• Hero Member
• Posts: 877
##### Re: Problems with time and Distance Help Please
« Reply #73 on: July 08, 2020, 02:51:22 am »
They are a;; great circle. Back i the day that's what they called it. Now their International Routes.

And no China doesn't  have a better system. Military GPS accuracy is reportedly down to inches, less than 12. Instrument landing come in 3 flavors. Cat I, Cat II and Cat III. Only the military lands Cat III. Cat III is zero visibility. Airlines can't do this for two reasons. The FAA won't allow it and if they landed in zero visibility how would they taxi to the gate. They would have to be towed. So they are required to have enough fuel to fly to their secondary and 45 min additional fuel.

"I'm sorry to hear that. I take it that is due to age related (health) issues ? "

It's due to eye sight. Stable but not repairable. My computer screen is a 50 1080 and I sit 6' from it and still have dificulty seeing the screen.
« Last Edit: July 08, 2020, 02:57:08 am by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
Windows 10 Pro 32-GB
Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

#### TRon

• Hero Member
• Posts: 536
##### Re: Problems with time and Distance Help Please
« Reply #74 on: July 08, 2020, 02:53:02 am »
In the attachment KLM 868 flight.
Screenshoot reduced to get below the 250 k restriction to bad quality.
I tried to discuss that problem but they are all stuck in the 80s.

No - that is not a great circle. No, no ...

Winni
Yes yes, that is the one that is weird. I was referring to https://www.flightradar24.com/data/aircraft/ph-bhe#24d390ac which looks much healthier to me.