Quote:
Hi, this may sound ridiculuos but i want to know how can i insert a
polygon into database, if i only know the radius of the polygon.
Like i have a polygon, centered at the origin, with radius, say 5. Now
how can i insert it into mysql database? I hope we need to know the
vertices of it before inserting.
How can this be achieved. |
Assuming:
- It's a regular polygon.
- The center is at (0,0).
- The radius of a polygon is the distance from the center to a vertex
(as opposed to the distance from the center to the closest point on
a side).
- One of the vertices is at (0,r) relative to the center.
Then in polar coordinates, all of the vertexes are distance r from
the origin. For an N-sided regular polygon, the angles are at
k*360/N degrees, where k varies from 0 to N-1. If one of the
vertices is at an arbitrary angle theta, add this to the angle for
each of the vertices, then reduce modulo 360 degrees.
Now convert to rectangular coordinates. If the center is not at
(0,0), add the coordinates of the center to each of the vertices.