Jump to content
The simFlight Network Forums

Determining if the FS Aircraft lies Inside a Specific Poly


Recommended Posts

I need to tell if the aircraft is inside a user definable polygon defined by a list of vertices (lat/lon values). The poly could be almost any shape. I guess this must have been solved already but I am scratching my head for a 'foolproof' method.

Any pointers would be much appreciated

Link to comment
Share on other sites

Taking each pair of polygon points in turn, calculate the signed angle between the vectors from the aircraft to the points and accumulate. If the absolute value of the result is greater than 180 degrees, the aircraft is inside the polygon, if it is less, it is outside.

George

Link to comment
Share on other sites

Hi George

Thank you very much :D :D Could you just clarify whay you mean by a signed angle - I presume it has to be positive. Also a quick sketch would seem to show that if the aircraft is inside the poly the sum of the angles should be 360, but that may just show I have mi-understood :)

EDIT. Hmm the 360 would not seem right if the poly is an L shape

Link to comment
Share on other sites

Hmm the 360 would not seem right if the poly is an L shape

Yes, I can assure you that it does work for any shaped polygon.

The signed angle means that all angles should be measured either clockwise or counterclockwise. Hint, use a vector cross-product.

George

Link to comment
Share on other sites

Here is an example. Taking pairs 1-2, 2-3 etc, the blue angles are positive and the red angles are negative. The sum should be zero, however with rounding errors I always use abs(sum) < 180.

Inside.jpg

George

Link to comment
Share on other sites

Thanks George - I understand how it works. I am not reading up on vector maths to code up the angle calculations. I was going to work out the bearing of each of the pairs from the aircraft and subtract the second from the first but that gets complicated around 360/0. Looks like using vectors and cross-products to calculate the angle is better as you suggest. I just digging up some information on that now - it is a long time since I did this kind of math :D

EDIT - OK I think I have coded it now I need to make a test rig.

Link to comment
Share on other sites

Hi folks,

I too have this problem but wasnt going to delve into it until I hit that part of my program. However, I have been reading up on vector cross products and from the advice I have been able to find it says that a VCP only applies to 3D vectors. Is this correct? Have I missed something?

Taking that further, how would this apply to a 3D problem. That is, determining if an aircraft is inside a block of airspace?

Cheers in advance.

Simon

Link to comment
Share on other sites

All vectors are 3D. For 2D, set the third component to zero which is quite adequate for small distances. If the block of airspace is delimited by two heights, you simply check as above then check max/min height. Unless the heights are wildly different, then you need to use spherical projection.

George

Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • 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.