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

Home » Public Forums » archive » Already written function to find if a point is within a rectangle?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Already written function to find if a point is within a rectangle? [message #79347] Mon, 20 February 2012 13:29 Go to next message
Jacare Omoplata is currently offline  Jacare Omoplata
Messages: 6
Registered: February 2012
Junior Member
Hi,

I'm working with some data that has been extracted from astronomical
images. All the stars in the images have been identified and their x
and y positions are recorded among other information. ( these x and y
position can be converted the Right Ascension (RA) and Declination
(DEC), so the position of the star in the sky can be found )

These images overlap. I want to plot the positions of all the stars
from all the images, but because of image overlaps, some points are
going to be counted twice. Since the RA and DEC are floating point
numbers, for the same star in two images they might be slightly
different. So using the RA and DEC to identify double counts is not
going to work.

I've come up with the following plan.

Start reading in stars by file. After reading each file, get the
boundaries of each image ( they are rectangular ) and store them. For
each star, check whether it is within the region of images already
read. If it is, don't read it in. If it does not lie within the
regions already read, read it in.

So I need a way to find out if a point ( position of a star ) is
within a rectangle ( image boundary ). The rectangle edges are not
strictly horizontal or vertical.

I've found several methods of doing this, and can write a function.
But I can save some time if someone knows if there's already one
available out there.

Thanks.
Re: Already written function to find if a point is within a rectangle? [message #79354 is a reply to message #79347] Fri, 24 February 2012 22:33 Go to previous messageGo to next message
Jacare Omoplata is currently offline  Jacare Omoplata
Messages: 6
Registered: February 2012
Junior Member
>
> I have a few routines for spherical polygons available:
>
> http://tir.astro.utoledo.edu/jdsmith/code/idl.php
>
> JD

Thanks! I will bookmark this page. These programs will definitely be
useful to me!
Re: Already written function to find if a point is within a rectangle? [message #79355 is a reply to message #79347] Fri, 24 February 2012 14:00 Go to previous messageGo to next message
JDS is currently offline  JDS
Messages: 94
Registered: March 2009
Member
On Thursday, February 23, 2012 2:13:18 PM UTC-5, Paulo Penteado wrote:
> On Feb 23, 7:34 am, Craig Markwardt <craig.markwa...@gmail.com> wrote:
>>> I'm thinking of making polygons with a large number of edges, instead
>>> of rectangles, with every data point at the edge of a FITS file as a
>>> vertex. That would minimize the projection error, right?
>>
>> That helps.  Special care is probably need around the poles though.
>
> Not only the poles. Also at the longitude boundary. Working with
> polygons in spherical geometry is, in my experience, a pain. Just
> because there is not enough library support for it.

I

On Thursday, February 23, 2012 2:13:18 PM UTC-5, Paulo Penteado wrote:
> On Feb 23, 7:34 am, Craig Markwardt <craig.markwa...@gmail.com> wrote:
>>> I'm thinking of making polygons with a large number of edges, instead
>>> of rectangles, with every data point at the edge of a FITS file as a
>>> vertex. That would minimize the projection error, right?
>>
>> That helps.  Special care is probably need around the poles though.
>
> Not only the poles. Also at the longitude boundary. Working with
> polygons in spherical geometry is, in my experience, a pain. Just
> because there is not enough library support for it.



On Thursday, February 23, 2012 2:13:18 PM UTC-5, Paulo Penteado wrote:
> On Feb 23, 7:34 am, Craig Markwardt <craig.markwa...@gmail.com> wrote:
>>> I'm thinking of making polygons with a large number of edges, instead
>>> of rectangles, with every data point at the edge of a FITS file as a
>>> vertex. That would minimize the projection error, right?
>>
>> That helps.  Special care is probably need around the poles though.
>
> Not only the poles. Also at the longitude boundary. Working with
> polygons in spherical geometry is, in my experience, a pain. Just
> because there is not enough library support for it.

I

On Thursday, February 23, 2012 2:13:18 PM UTC-5, Paulo Penteado wrote:
> On Feb 23, 7:34 am, Craig Markwardt <craig.markwa...@gmail.com> wrote:
>>> I'm thinking of making polygons with a large number of edges, instead
>>> of rectangles, with every data point at the edge of a FITS file as a
>>> vertex. That would minimize the projection error, right?
>>
>> That helps.  Special care is probably need around the poles though.
>
> Not only the poles. Also at the longitude boundary. Working with
> polygons in spherical geometry is, in my experience, a pain. Just
> because there is not enough library support for it.



On Thursday, February 23, 2012 2:13:18 PM UTC-5, Paulo Penteado wrote:
> On Feb 23, 7:34 am, Craig Markwardt <craig.markwa...@gmail.com> wrote:
>>> I'm thinking of making polygons with a large number of edges, instead
>>> of rectangles, with every data point at the edge of a FITS file as a
>>> vertex. That would minimize the projection error, right?
>>
>> That helps.  Special care is probably need around the poles though.
>
> Not only the poles. Also at the longitude boundary. Working with
> polygons in spherical geometry is, in my experience, a pain. Just
> because there is not enough library support for it.

I have a few routines for spherical polygons available:

http://tir.astro.utoledo.edu/jdsmith/code/idl.php

JD
Re: Already written function to find if a point is within a rectangle? [message #79356 is a reply to message #79347] Fri, 24 February 2012 10:48 Go to previous messageGo to next message
Jacare Omoplata is currently offline  Jacare Omoplata
Messages: 6
Registered: February 2012
Junior Member
On Feb 23, 1:05 pm, Greg Hennessy <greg.henne...@cox.net> wrote:
>>> I'm thinking of making polygons with a large number of edges, instead
>>> of rectangles, with every data point at the edge of a FITS file as a
>>> vertex. That would minimize the projection error, right?
>
>> That helps.  Special care is probably need around the poles though.
>
> It often helps to convert from ra/dec to unit vectors
> ([cos(ra)*cos(dec),sin(ra)*cos(dec),sin(dec)]) for both
> the star position and the edges of the polygon.

That's brilliant idea!

I'm not going to bother with it for this problem, since I've already
half written the program, and the images are not near the poles or the
longitude boundary. I will definitely use it in the future though.

Thanks.
Re: Already written function to find if a point is within a rectangle? [message #79388 is a reply to message #79347] Thu, 23 February 2012 11:13 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Feb 23, 7:34 am, Craig Markwardt <craig.markwa...@gmail.com> wrote:
>> I'm thinking of making polygons with a large number of edges, instead
>> of rectangles, with every data point at the edge of a FITS file as a
>> vertex. That would minimize the projection error, right?
>
> That helps.  Special care is probably need around the poles though.

Not only the poles. Also at the longitude boundary. Working with
polygons in spherical geometry is, in my experience, a pain. Just
because there is not enough library support for it.
Re: Already written function to find if a point is within a rectangle? [message #79391 is a reply to message #79347] Thu, 23 February 2012 10:05 Go to previous messageGo to next message
Greg Hennessy is currently offline  Greg Hennessy
Messages: 45
Registered: November 2005
Member
>> I'm thinking of making polygons with a large number of edges, instead
>> of rectangles, with every data point at the edge of a FITS file as a
>> vertex. That would minimize the projection error, right?
>
> That helps. Special care is probably need around the poles though.

It often helps to convert from ra/dec to unit vectors
([cos(ra)*cos(dec),sin(ra)*cos(dec),sin(dec)]) for both
the star position and the edges of the polygon.
Re: Already written function to find if a point is within a rectangle? [message #79398 is a reply to message #79347] Thu, 23 February 2012 01:34 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Feb 22, 10:25 pm, Jacare Omoplata <walkeystal...@gmail.com> wrote:
>>>> So I need a way to find out if a point ( position of a star ) is
>>>> within a rectangle ( image boundary ). The rectangle edges are not
>>>> strictly horizontal or vertical.
>
>>> You talk about coordinates in RA and dec. So are the images really
>>> rectangular? It seems to me that the real problem is that you need to
>>> deal with spherical geometry.
>
>> Not only that, but an "image boundary" will be projection-dependent
>> [*].  For small images it probably won't matter much, but there will
>> always be an edge case that gets you later.
>
> I'm thinking of making polygons with a large number of edges, instead
> of rectangles, with every data point at the edge of a FITS file as a
> vertex. That would minimize the projection error, right?

That helps. Special care is probably need around the poles though.

Craig
Re: Already written function to find if a point is within a rectangle? [message #84292 is a reply to message #79354] Sat, 18 May 2013 21:19 Go to previous message
suruchi is currently offline  suruchi
Messages: 13
Registered: September 2012
Junior Member
On Saturday, February 25, 2012 12:03:47 PM UTC+5:30, Jacare Omoplata wrote:
>>
>
>> I have a few routines for spherical polygons available:
>
>>
>
>> http://tir.astro.utoledo.edu/jdsmith/code/idl.php
>
>>
>
>> JD
>
>
>
> Thanks! I will bookmark this page. These programs will definitely be
>
> useful to me!

Hi Jacare
I have been looking for finding overlap of two polygons covering some regions on solar disc images defined in terms of latitude and longitudes. Hence here also spherical geometry comes into picture.. how to match the latitudes and longitudes? Could you suggest how can I achieve this?
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: calling ANSYS Fluent from IDL
Next Topic: Youtube

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

Current Time: Wed Oct 08 13:38:34 PDT 2025

Total time taken to generate the page: 0.00616 seconds