/// <summary>
/// create a new circle geometry, which is polygon, depending on the given center and radius
/// @diligentpig
/// @http://newnaw.com
/// </summary>
/// <param name="ptCenter">center of the newly created circle.</param>
/// <param name="dRadius">radius of the newly created circle, in screen pixel.</param>
/// <param name="n">precision, represents how many point does the return polygon have. These points are symmetrily located.
/// if n=0, then transfer to default precision which n=32</param>
/// <param name="map">the map control, used for converting mappoint to screenpoint and vice versa.</param>
/// <returns>a polygon geometry simulate a circle</returns>
public static Polygon createCirclePolygon(MapPoint ptCenter, double dRadius, int n,ESRI.ArcGIS.Client.Map map)
{
PointCollection pc = new PointCollection();
System.Windows.Point ptCenterScreen = map.MapToScreen(ptCenter);
n = n <= 0 ? 32 : n;
for (int i = 0; i < n; i++)
{
//ecah point on the circle, counterclockwise
double angle = (Math.PI * 2) / n * i;
System.Windows.Point p = new System.Windows.Point()
{
X = ptCenterScreen.X + dRadius * Math.Cos(angle),
Y = ptCenterScreen.Y + dRadius * Math.Sin(angle)
};
pc.Add(map.ScreenToMap(p));
};
//add the last, which is exact the first, point.
pc.Add(map.ScreenToMap(new System.Windows.Point()
{
X=ptCenterScreen.X+dRadius,
Y=ptCenterScreen.Y
}));
Polygon polyg = new Polygon()
{
SpatialReference=map.SpatialReference
};
polyg.Rings.Add(pc);
return polyg;
}