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

Home » Public Forums » archive » Re: Points in a rectangle with an angle
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: Points in a rectangle with an angle [message #48226 is a reply to message #48222] Wed, 05 April 2006 09:53 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
JJMeyers2@gmail.com writes:
> Hello,
>
> I have a problem in IDL that I was wondering if anyone has any idea how
> it can be done.
> I have a set of coordinates and I am trying to figure out how many of
> the coordinates are inside a rectangle. I know the coordinates of the 4
> edges of the rectangle but the problem is that the rectangle is at an
> angle in the x,y axis ( I know the slope). I can not just say
> coords=where((x LE xmax) AND (x GT xmin) AND (y LE ymin) AND (y GT
> ymax))
> because that will give me coordinates of a rectangle without an angle
> (parallel to the y axis).
> Is there any function in IDL that might be doing that?

Not really, but it's pretty easy to do yourself.

Assume that the rectangle is centered at (XCENT,YCENT) and has a WIDTH
and HEIGHT in its body coordinate system. Also, assume that the
rectangle is rotated THETA degrees counterclockwise from the "world" X axis.

;; Translate to center-of-box coordinates (xp,yp)
xp = x - xcent
yp = y - ycent
;; Rotate into box coordinates (u,v)
u = cos(theta*!dtor)*xp - sin(theta*!dtor)*yp
v = sin(theta*!dtor)*xp + cos(theta*!dtor)*yp
;; Do the selection
wh = where(abs(u) LT width/2 AND abs(v) LT height/2)

This takes advantage of the fact that in center-of-box coordinates,
half of the box is left and right of the origin, and above and below
the origin. The only tricky part is getting the signs right, which I
think I did.

Craig



--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Shared Memory in Windows
Next Topic: Re: iTools/interactive Analysis >

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

Current Time: Wed Oct 08 13:56:33 PDT 2025

Total time taken to generate the page: 0.14804 seconds