You need to be checking each boundry of the runway as opposed to just checking if it's in the four corners like you're doing at the moment.

The main thing you need to find out is the latitudes of the edges of the runway at the plane's current longitude and vice verse.

I've attached a graphic to show the maths for one boundry (NW/SW).

(the lon/lat units have been simplified to make things clearer)

We know the plane is at Lon 23.5E. But at what longitude is the edge of the runway at the current aircraft Latitude (24N)?

To find out we use some basic trigonometry with right angled triangles...

1. We know the positions of the NW corner and SW corner. From this we can get the lengths of two sides of the triangle. (Blue numbers)

2. The ratio between these side is 10:5 = 2:1.

3. What we want to know is: How far across is the edge of the runway at 24N. ('X' on the diagram). 24N is only 6 south of from the NW latitude . This forms a smaller triangle inside the larger one. (In red)

4. The ratio of the sides of this smaller triangle will be the same at the larger one (2:1).

5. To if the long edge is 6 the short one will be 6/2 which is 3.

6. Add that distance to the NW longitude (20E) and you get the absolute longitude of where the runway starts. In this case 23E.

7. Since the aircraft is at 23.5E it's east of the west boundry and so we could be on the runway.

You just do similar calculations for the other 4 boundries.

If they all pass, you're on the runway.

So here's a routine that will check if a point is within a quadrangle. This even works if the sides arn't parralel.

It's important that you enter the corordinates of the four corners correctly or it won't work. They are labeled NW, NE, SW and SE. Just make sure your map is pointing north and it should be fairly easy to work out which is which.

C#

private bool AreaContainsPoint(double AreaNELat, double AreaNELon, double AreaSELat, double AreaSELon, double AreaSWLat, double AreaSWLon, double AreaNWLat, double AreaNWLon, double PointLat, double PointLon) { bool InArea = false; // Check if point is EAST of the NW/SW boundry if (PointLon > AreaNWLon + ((AreaSWLon - AreaNWLon) / (AreaNWLat - AreaSWLat) * (AreaNWLat - PointLat ))) { // Check if point is WEST of the NE/SE boundry if (PointLon < AreaNELon + ((AreaSELon - AreaNELon) / (AreaNELat - AreaSELat) * (AreaNELat- PointLat))) { // Check if point is NORTH of the SW/SE boundry if (PointLat > AreaSWLat + ((AreaSELat - AreaSWLat) / (AreaSELon - AreaSWLon) * (PointLon - AreaSWLon))) { // Check if point is South of the NW/NE boundry InArea = (PointLat < AreaNWLat + ((AreaNELat - AreaNWLat) / (AreaNELon - AreaNWLon) * (PointLon - AreaNWLon))); } } } return InArea; }

VB.NET

Private Function AreaContainsPoint(ByVal AreaNELat As Double, ByVal AreaNELon As Double, ByVal AreaSELat As Double, ByVal AreaSELon As Double, ByVal AreaSWLat As Double, ByVal AreaSWLon As Double, ByVal AreaNWLat As Double, ByVal AreaNWLon As Double, ByVal PointLat As Double, ByVal PointLon As Double) As Boolean Dim InArea As Boolean = False ' Check if point is EAST of the NW/SW boundry If (PointLon > AreaNWLon + ((AreaSWLon - AreaNWLon) / (AreaNWLat - AreaSWLat) * (AreaNWLat - PointLat))) Then ' Check if point is WEST of the NE/SE boundry If (PointLon < AreaNELon + ((AreaSELon - AreaNELon) / (AreaNELat - AreaSELat) * (AreaNELat - PointLat))) Then ' Check if point is NORTH of the SW/SE boundry If (PointLat > AreaSWLat + ((AreaSELat - AreaSWLat) / (AreaSELon - AreaSWLon) * (PointLon - AreaSWLon))) Then ' Check if point is South of the NW/NE boundry InArea = (PointLat < AreaNWLat + ((AreaNELat - AreaNWLat) / (AreaNELon - AreaNWLon) * (PointLon - AreaNWLon))) End If End If End If AreaContainsPoint = InArea End Function

It's also worth noting that this assumes the earth is flat. That's probably not a problem with checking a small area like a runway. The larger the area you check, the more inaccurate it becomes because of the roundness of the earth. The maths to do it property taking into account the round earth is fairly complicated.

Hope this works.

I've started to put Lon/Lat support in the .NET client DLL. I'll put this in there as well. Can't say when I'll get time to finish it off though.

Let me know how it goes...

Paul