scruffyduck Posted April 6, 2006 Report Share Posted April 6, 2006 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 More sharing options...
GHD Posted April 6, 2006 Report Share Posted April 6, 2006 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 More sharing options...
scruffyduck Posted April 6, 2006 Author Report Share Posted April 6, 2006 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 More sharing options...
GHD Posted April 6, 2006 Report Share Posted April 6, 2006 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 More sharing options...
scruffyduck Posted April 6, 2006 Author Report Share Posted April 6, 2006 OK Thanks George I understand that now Link to comment Share on other sites More sharing options...
GHD Posted April 6, 2006 Report Share Posted April 6, 2006 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. George Link to comment Share on other sites More sharing options...
scruffyduck Posted April 6, 2006 Author Report Share Posted April 6, 2006 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 More sharing options...
Simon Rigby Posted April 11, 2006 Report Share Posted April 11, 2006 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 More sharing options...
GHD Posted April 11, 2006 Report Share Posted April 11, 2006 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 More sharing options...
Simon Rigby Posted April 11, 2006 Report Share Posted April 11, 2006 Ah of course. Yes I understand. Many thanks George. Simon Link to comment Share on other sites More sharing options...
Rhysa Posted May 9, 2006 Report Share Posted May 9, 2006 I had a similar problem, and the solution I use can be found here http://mathforum.org/library/drmath/view/54386.html. I use the matrix method down the bottom of the page, it works great for simple polygons. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now