The condition that the zero point is inside the polygon is that the winding 
angle is nonzero.
   zero_inside_polygon =. [:nonzero winding
The nonzero condition must be tolerant because rounding errors may make a 
theoretical zero look like nonzero. But nonzero winding angles are integer 
multiples of 0j2p1, so a robust condition is

   nonzero=.[:>&1|
A simple winding angle algorithm is
   winding=.[:+/[:^.(%1&|.)
   plot(,{.)p2=.0.1++:p,+:+p=.0j1^i.4NB. p2 =. nonconvex test polygon
   zero_inside_polygon p2+3
1
   zero_inside_polygon p2
0   zero_inside_polygon f. NB. final program (25 chars)

[:([:>&1|)[:+/[:^.(%1&|.)






>________________________________
> Fra: Ian Clark <earthspo...@gmail.com>
>Til: Programming forum <programming@jsoftware.com> 
>Sendt: 17:17 søndag den 13. maj 2012
>Emne: Re: [Jprogramming] Irregularly shaped buttons
> 
>Thanks, Bo, that gets me on a bit!
>
>On Sat, May 12, 2012 at 8:36 PM, Bo Jacoby <bojac...@yahoo.dk> wrote:
>> The winding number program is written and tested, and does not assume the 
>> polygon to be convex.
>>
>>    rd=.(**|)&.+. NB. round complex number
>>    W=.rd@(%&0j2p1)@(+/)@:^.@(% _1&|.)NB. winding number
>>    p=.0j1^i.4 NB. test polygon
>>    rd p NB. display test polygon vertices
>> 1 0j1 _1 0j_1
>>    load'plot'
>>
>>    plot (,{.)p NB. show polygon
>>    W p-2 NB. 2 is outside polygon
>> 0
>>    W p-0 NB. 0 is inside polygon
>> 1
>>
>>
>>
>>
>>
>>>________________________________
>>> Fra: Ian Clark <earthspo...@gmail.com>
>>>Til: Programming forum <programming@jsoftware.com>
>>>Sendt: 17:38 lørdag den 12. maj 2012
>>>Emne: Re: [Jprogramming] Irregularly shaped buttons
>>>
>>>Thanks, everyone. Plenty of ideas here.
>>>
>>>Lazy me: I was angling for some written & tested code. But at least I
>>>know I won't be wasting my time reinventing the wheel.
>>>
>>>The "polygon" can't be assumed convex. In fact, since I'd like to
>>>accommodate the most general shape, I'm going with either a binary
>>>pixel mask (the crudest, easiest solution) or detecting the underlying
>>>pixel color upon mouseclick.
>>>
>>>
>>>On Fri, May 11, 2012 at 5:41 PM, 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
>
>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to