comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: point inside polygon
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: point inside polygon [message #11504 is a reply to message #11494] Wed, 01 April 1998 00:00 Go to previous messageGo to previous message
B}rd Krane is currently offline  B}rd Krane
Messages: 5
Registered: April 1997
Junior Member
Alex Schuster wrote:
>
> William Connolley wrote:
>
>> In article C0684CDB@oma.be, Philippe Peeters <philp@oma.be> writes:
>>> Does anybody knows of an IDL function to test whether a given point is
>>> inside a polygon?
>>
>> I needed to solve this recently (in a mapping context). The solution I came up
>> with works but its not elegant: use poly_fill to actually draw your polygon
>> (in a pixmap not the screen window if you prefer), then read off the pixel value
>> of your point to see if its in or out.
>>
>> This is grotesquely inelegant, but its very simple and it works. I can
>> post the code if you're interested. A better solution
>> would be to look at polyfill and see how it does the fill... but sadly
>> polyfill seems to be one of the few routines not written in IDL.
>

This function determines if a point is inside a polygon or not. If you
have
several points I believe you are better off with the polyfillv approach.
Baard


FUNCTION inside, x, y, px, py

sx = size(px)
sy = size(py)
IF (sx[0] EQ 1) THEN NX=sx[1] ELSE return,-1 ; error if px not a
vector
IF (sy[0] EQ 1) THEN NY=sy[1] ELSE return,-1 ; error if py not a
vector
IF (NX EQ NY) THEN N = NX ELSE return,-1 ; Incompatible
dimensions

tmp_px = [px, px[0]] ; Close Polygon in x
tmp_py = [py, py[0]] ; Close Polygon in y

i = indgen(N) ; indices 0...N-1
ip = indgen(N) + 1 ; indices 1...N

X1 = tmp_px(i) - x & Y1 = tmp_py(i) - y
X2 = tmp_px(ip) - x & Y2 = tmp_py(ip) - y

dp = X1*X2 + Y1*Y2 ; Dot-product
cp = X1*Y2 - Y1*X2 ; Cross-product
theta = atan(cp,dp)

IF (abs(total(theta)) GT 1.0E-8) THEN return,1 ELSE return,0
END
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Volume Size
Next Topic: Re: Three questions

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:44:09 PDT 2025

Total time taken to generate the page: 0.00404 seconds