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 #11495 is a reply to message #11494] Wed, 01 April 1998 00:00 Go to previous messageGo to previous message
wmc is currently offline  wmc
Messages: 117
Registered: February 1995
Senior Member
In article DF0F2DFA@fys.uio.no, "B�rd Krane" <bard.krane@fys.uio.no> writes:
> 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
(some bits cut)
> sx = size(px)
> sy = size(py)
> N=sx(1)
> 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

Interesting... there had to be a better way and this looks like it.
I'm now trying to work out why it works... I think you're counting up the angles
going round the polygon to the point, and the sum is zero outside and 2*!pi
inside.

Only one criticism: 1e-8 is too tight a test for single precision:
inside(.5,1.5,[0,1,1,0],[0,0,1,1]) returns 1
since total(theta) is -1.19e-7.
But inside(.5,1.5d0,[0,1,1,0],[0,0,1,1]) returns 0 as it should.
So I think the test should be 1e-5 or somesuch (though presumably .1 would work
just as well?).

- William

---
William M Connolley | wmc@bas.ac.uk | http://www.nbs.ac.uk/public/icd/wmc/
Climate Modeller, British Antarctic Survey | Disclaimer: I speak for myself
[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: Thu Oct 09 22:31:49 PDT 2025

Total time taken to generate the page: 0.72336 seconds