Re: Points in a rectangle with an angle [message #48222] |
Thu, 06 April 2006 04:37 |
Maarten[1]
Messages: 176 Registered: November 2005
|
Senior Member |
|
|
JJMeyers2@gmail.com wrote:
> 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))
If you named your variables correctly, that should never return a value
;)
> 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?
You may want to check out the IDLanROI object. Works on vectors as
well, even in 3D.
Maarten
|
|
|
Re: Points in a rectangle with an angle [message #48226 is a reply to message #48222] |
Wed, 05 April 2006 09:53  |
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
------------------------------------------------------------ --------------
|
|
|
|
Re: Points in a rectangle with an angle [message #48228 is a reply to message #48226] |
Wed, 05 April 2006 09:43  |
K. Bowman
Messages: 330 Registered: May 2000
|
Senior Member |
|
|
In article <1144254765.987764.323760@i39g2000cwa.googlegroups.com>,
JJMeyers2@gmail.com wrote:
> 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?
>
> Thank you,
> JJM.
If you know the angle of the rectangle, rotate your coordinate system, then use
the simple comparison that you give above.
Ken Bowman
|
|
|
Re: Points in a rectangle with an angle [message #48229 is a reply to message #48228] |
Wed, 05 April 2006 09:58  |
Rick Towler
Messages: 821 Registered: August 1998
|
Senior Member |
|
|
This is the classic point in polygon test. There are two common
approaches, the crossing test and the winding test. You can google this
for the specifics but here are a few pages to get you started:
http://softsurfer.com/Archive/algorithm_0103/algorithm_0103. htm
I've used this in the past:
http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/p npoly.html
There are probably ways to IDLize this but I implemented this in a DLM
so I never gave it any thought.
I would suggest a 2 stage approach:
first do your rough cull using WHERE to get a subset of points that
*may* be in your polygon. Then do the fine cull with a point in polygon
test of your choosing. You have a pretty simple case (2d, 4 vertex
polygon) so you could get away with a pretty simple test.
-Rick
JJMeyers2@gmail.com wrote:
> 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?
>
> Thank you,
> JJM.
>
|
|
|
Re: Points in a rectangle with an angle [message #48230 is a reply to message #48228] |
Wed, 05 April 2006 09:48  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
JJMeyers2@gmail.com writes:
> 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?
http://www.dfanning.com/tips/point_in_polygon.html
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|