Re: Geometric data type for an arc.
От | Binand Sethumadhavan |
---|---|
Тема | Re: Geometric data type for an arc. |
Дата | |
Msg-id | CAFBJCCacmt0CV3ZNhjwWtY0rsrW69cwMmV1O+FTwRJQS-0XjVg@mail.gmail.com обсуждение исходный текст |
Ответ на | Geometric data type for an arc. ("John W. Kitz" <John.Kitz@xs4all.nl>) |
Ответы |
Re: Geometric data type for an arc.
|
Список | pgsql-novice |
On 10 May 2012 16:24, John W. Kitz <John.Kitz@xs4all.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
В списке pgsql-novice по дате отправления: