From: | Alexander Korotkov <aekorotkov(at)gmail(dot)com> |
---|---|
To: | Erik Wienhold <ewie(at)ewie(dot)name> |
Cc: | Thomas Simpson <ts(at)talentstack(dot)to>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: circle @> box, polygon points access |
Date: | 2024-11-21 22:23:48 |
Message-ID: | CAPpHfduh3y_vNoacPt3KGGz5r5PgZAhXPvg7U4axoC90ubiP3Q@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, Nov 22, 2024 at 12:05 AM Erik Wienhold <ewie(at)ewie(dot)name> wrote:
>
> On 2024-11-21 19:18 +0100, Thomas Simpson wrote:
> > Looking through the archives, around 20 years ago someone asked about
> > getting a list of points from a polygon [15 AUG 2004] and the reply was this
> > was not available but something like point(polygon, n) could be added
> > relatively easily as a new feature to extract points.
> >
> > I'm hitting an issue trying to check if a box is entirely contained within a
> > circle and I had thought since that comparison is not directly supported to
> > cast the box to a polygon and then check each of the points in the polygon
> > since that is what the circle containing a box is essentially going to do.
> >
> > However, there does not seem to be an easy way to access the polygon
> > elements either (unnest failed, indexing doesn't work and the point(poly,n)
> > is not there).
> >
> > Can anyone point me to an approach to do what I need or is this going to be
> > best by adding the box comparison in the mainline code? I'm happy to take a
> > go if someone points [no pun intended] me to where in the code to go.
>
> You can treat point and box as arrays to access their components. See
> the very last paragraph on [1]. That requires extra parenthesis,
> though:
>
> regress=# select ((box '(1,2),(3,4)')[0])[0];
> box
> -----
> 3
> (1 row)
>
> But you'd have to calculate the remaining two points.
And the circle can be transformed to the box. Then all parameters of
the circle could be calculated. Awkward, but could work.
> I think your specific use case (Is box in a circle?) can be also be
> answered by considering the smallest enclosing circle of that box and
> test if that circle is contained in your input circle. For example:
>
> regress=# select circle(box '(1,2),(3,4)') <@ circle '(0,0),10';
> ?column?
> ----------
> t
> (1 row)
Oh, that's not true. Check the picture attached.
------
Regards,
Alexander Korotkov
Supabase
Attachment | Content-Type | Size |
---|---|---|
pic.png | image/png | 142.7 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Nathan Bossart | 2024-11-21 22:25:38 | Re: Parametrization minimum password lenght |
Previous Message | Erik Wienhold | 2024-11-21 22:05:27 | Re: circle @> box, polygon points access |