en.wikipedia.org/wiki/Wikipedia:Reference_desk/Archives/Mathematics/2009_December_17#Easiest_way_to_decide_if_a_point_is_within_a_polygon.3F says:
The J (programming language) allows this short implementation of the winding number formula: W=.9&o.@(%&0j2p1)@(+/)@:^.@(% _1&|.) . To test if (0,0) is within the square ((1,0),(0,1),(-1,0),(0,-1)), type W 1 0j1 _1 0j_1 and get the result 1, indicating YES. To test if (4,0) is within the square, type W 1 0j1 _1 0j_1 - 4 and get the result 0, indicating NO. >________________________________ > Fra: Don Guinn <dongu...@gmail.com> >Til: Programming forum <programming@jsoftware.com> >Sendt: 22:54 fredag den 11. maj 2012 >Emne: Re: [Jprogramming] Irregularly shaped buttons > >I made a form of parking spaces in a RV storage facility. Each space was a >button and irregularly shaped and at odd angles. > >As you suggested given a mouse click, I selected all potential shapes close >for performance. To determine which shape the click actually was I took all >adjacent corners of a shape and formed triangles with the click. Then >computed the areas of these triangles. If all areas are positive (or >negative, depending which way you order the corners) the click is within >the shape. This only works if the shapes are convex. >On May 11, 2012 10:42 AM, "Ian Clark" <earthspo...@gmail.com> wrote: > >> To save me reinventing the wheel, has anybody written routines to act >> on mouseclicks inside irregularly-shaped "buttons"? >> >> Techniques I'm considering: >> >> ++ Detecting if a point is inside an arbitrary polygon >> >> ++ Unions and differences of rectangles, triangles and sectors >> >> ++ Color of the pixel under the cursor >> >> If it works on a simple map of the USA, it'll probably work for my purpose. >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> >---------------------------------------------------------------------- >For information about J forums see http://www.jsoftware.com/forums.htm > > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm