Skip site navigation (1)
Skip section navigation (2)
## Re: Geometric data type for an arc.

### Responses

### pgsql-novice by date

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!): https://picasaweb.google.com/112929706764240025005/STUFF#5740866485548434802 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

- Re: Geometric data type for an arc. at 2012-05-10 13:48:49 from John W. Kitz
- Re: Geometric data type for an arc. at 2012-05-10 14:04:56 from Simone Sanfratello

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