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

Home » Public Forums » archive » Re: A distracting puzzle
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: A distracting puzzle [message #26729 is a reply to message #26683] Tue, 25 September 2001 09:11 Go to previous message
Stein Vidar Hagfors H[1] is currently offline  Stein Vidar Hagfors H[1]
Messages: 56
Registered: February 2000
Member
If what's being sought here is only to distinguish which pixels have *some*
area inside the polygon and which do not, wouldn't it be sufficient to check
the corners? I.e., in a continuum of pixel coordinates, given corners with
coordinates [0,0], [1,0], [1,1], [0,1], it can be checked whether each of
those are inside versus outside any defined polygon. If one or more of the
corners is inside, then some area is also inside..

I have included some simple-minded routines I wrote some years ago to check
whether a point is inside or outside a polygon...

Stein Vidar

---------------------

;; $Id: vectorangle.pro,v 1.1 1999/06/02 16:24:14 steinhh Exp $
;;The angle between vector A & B
;; The angle that vector A needs to be rotated (counterclockwise) in order
;; to be parallell to B

FUNCTION vectorangle,x1,y1,x2,y2,zerovalue=zerovalue

default,zerovalue,0.0

dp = x1*x2 + y1*y2
cp = x1*y2 - x2*y1

ix = where(dp EQ 0 AND cp EQ 0)
IF ix(0) EQ -1L THEN return,atan(cp,dp)*!radeg

dp(ix) = 1.0
res = atan(cp,dp)*!radeg
res(ix) = zerovalue
return,res

END

-----------------------

;; $Id: insidepolygon.pro,v 1.2 1999/06/02 16:25:59 steinhh Exp $
;; Return true if the given point is inside the
;;

;; Poly == [2,N]

FUNCTION insidepolygon,ip,x,y,$
edge_is_inside=edge_is_inside

IF size(ip,/type) NE 4 AND size(ip,/type) NE 5 THEN p = float(ip) $
ELSE BEGIN
copyback = 1
p = temporary(ip)
END

np = (size(p))(2)

x1 = p(0,*)-x
y1 = p(1,*)-y
x2 = shift(p(0,*),0,-1)-x
y2 = shift(p(1,*),0,-1)-y

zeroval = 1e5
theta = vectorangle(x1,y1,x2,y2,zerovalue=zeroval)

ix = where(theta EQ zeroval $
OR abs(theta-180.0d) LT 1e-4 $
OR abs(theta+180.0d) LT 1e-4,count)
IF count GT 0 THEN BEGIN
result = keyword_set(edge_is_inside)
GOTO,finished
END

;; Test for those....

result = abs(total(theta)) GT 180.0

finished:

IF copyback THEN ip = temporary(p)

return,result
END
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Object Graphics --> EPS Output how?
Next Topic: Text Widget Confession

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

Current Time: Fri Oct 10 10:48:18 PDT 2025

Total time taken to generate the page: 1.44076 seconds