Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Estimating a circle using a polygon

Tags: polygon
A Circle is a very commonly required geometric when plotting/processing spatial data. But somehow most of the available spatial processing tools do not give you a ready circle geometry or provide a very crude implementation. So we generally end up estimating a circle geometry using a Polygon. In short we draw a polygon with all its vertices lying on the circle you want to represent. The number of sides your polygon has depends on the accuracy you need for the circle. A 32 side polygon with correctly plotted points is considered an near perfect circle.

Here's working java code for getting the edges of such a polygon, given the radius and center of the circle.

public Coordinate[] getCircle(Double lat,Double lng, Double radius)
{

int points = 32;
Double d2r = Math.PI / 180;   // degrees to radians
Double r2d = 180 / Math.PI;   // radians to degrees
Double earthsradius = 3963.0;
Double rlat = (radius / earthsradius) * r2d;
Double rlng = rlat / Math.cos(lat * d2r);

Coordinate[] list = new Coordinate[points+1];
for(int i=0;i

   Double theta = (double)i/(double)points * 2 *Math.PI;
   Double ey = lng + (rlng * Math.cos(theta));
   Double ex = lat + (rlat * Math.sin(theta));
   list[i] = new Coordinate(ex,ey);

}
// make sure the circle is complete
list[points]=list[0];

return list;
}



This post first appeared on As I See It, please read the originial post: here

Share the post

Estimating a circle using a polygon

×

Subscribe to As I See It

Get updates delivered right to your inbox!

Thank you for your subscription

×