Estimating a circle using a polygon
Posted by
shashank ( shantaram )
Estimating a circle using a 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.
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;
}
Friday, June 21, 2013 | 0 Comments
Subscribe to:
Posts (Atom)