## Re: Geometric data type for an arc.

From: Binand Sethumadhavan John(dot)Kitz(at)xs4all(dot)nl pgsql-novice(at)postgresql(dot)org Re: Geometric data type for an arc. 2012-05-10 11:36:50 CAFBJCCacmt0CV3ZNhjwWtY0rsrW69cwMmV1O+FTwRJQS-0XjVg@mail.gmail.com (view raw, whole thread or download thread mbox) 2012-05-10 11:36:50 from Binand Sethumadhavan  2012-05-10 13:48:49 from "John W(dot) Kitz"  2012-05-10 14:04:56 from Simone Sanfratello   2012-05-10 15:10:36 from "John W(dot) Kitz"   2012-05-10 16:02:03 from Merlin Moncure    2012-05-10 16:59:23 from Tom Lane     2012-05-10 17:07:10 from Merlin Moncure pgsql-novice
```On 10 May 2012 16:24, John W. Kitz <John(dot)Kitz(at)xs4all(dot)nl> wrote:
> What would be the easiest way to store in PostgreSQL an arc or partial
> circle, defined by the two coordinates of a center point, the two
> coordinates of the two end points of the arc and the radius of the circle of
> which the arc is a part?

This doesn't uniquely define the arc, you know. This defines two arcs
(plus the radius is redundant, since it is also the distance between
the centre and one of the points and can be computed from the given
coordinates).

I'd imagine the canonical way of storing an arc of a circle in a DB
would be to store the circle to which the arc belongs to (see link you
posted) along with the angles the two radii to the end points of the
arc have with the positive X axis, and an indicator as to which of the
two arcs you intended. The angles can be calculated as invsin(y/r) for
each of the points where r is the radius.

Take a look at this picture (MS Paint, sorry!):

You know the coordinates of C (c1, c2) and A & B ((a1, a2) and (b1,
b2) respectively), as well as r, the radius of the circle.

The first thing to do is to perform these sanity checks:

r^2 = (a1-c1)^2 + (a2-c2)^2
r^2 = (b1-c1)^2 + (b2-c2)^2

Assuming they are fine, the idea is to store the circle itself
(completely identified by coordinates of the centre and the radius),
and the angles ACD and BCD. These angles can be calculated by:

ACD = invsin((a2-c2)/r)
BCD = invsin((b2-c2)/r)

The last piece of information needed is to know which of the two arcs
- the small one or the big one - you are interested in. You can do
this by convention, by saying that you will traverse the circle in the
counter-clockwise direction and the angle stored in the first column
in the database is that of the first endpoint encountered while
traversing.

The reverse calculation is equally simple:

For A:

x = c1 + r . cos ACD
y = c2 + r . sin ACD

For B:

x = c1 + r . cos BCD
y = c2 + r . sin BCD

Binand

```

### pgsql-novice by date

 Next: From: Shawn Matthews Date: 2012-05-10 12:43:30 Subject: I am NOT a programmer! Previous: From: John W. Kitz Date: 2012-05-10 10:54:39 Subject: Geometric data type for an arc.