Radius of a circle drawn as a polygon

8048
15
08-05-2013 11:10 AM
KunalMehta
New Contributor II
All,

I found this solution to draw a circle as a polygon of 360 points:

-(AGSPolygon*) circleWithCenter:(AGSPoint*)point raduis:(double)radius
{
    AGSMutablePolygon * p = [AGSMutablePolygon new];
    [p addRingToPolygon];
    int pointsCount = 360;
    double slice = 2 * M_PI / pointsCount;
    for(int i = 0; i<pointsCount;i++){
        double rad = slice * i;
        double px = point.x + radius * cos(rad);
        double py = point.y + radius * sin(rad);
        [p addPointToRing:[AGSPoint pointWithX:px y:py spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]]];
    }
   
    return p;
}


The question I have is what is the units of the radius passed in? For example, if I want to draw a circle of raduis 10 miles, what value do I pass in? If I pass in 10, it just draws a really huge circle with radius several multiples of 10!

I tried to look into the sdk api docs and could not find much info, so any help will be appreciated.
0 Kudos
15 Replies
Nicholas-Furness
Esri Regular Contributor

Ah. That's a very different question.

You should use Polygon.getCentroid() to get the centerpoint of the circle.

Then use Polygon.getPoint(0,0) to get a Point from the circle and use geometryEngine.distance() between the two points to determine the radius.

That assumes you used the Draw.CIRCLE type when you call draw.activate().

Please note that you appear to be using the draw-end event and it seems that is deprecated in favor of the draw-complete event.

0 Kudos
FancyAugustin
New Contributor II

Thank you  this was really useful.

one more clarification.

I saw the below format in tutorial:

distance(geometry1, geometry2, distanceUnit)

geometry.getPoint(0,0)
Object {type: "point", x: -15849192.693999259, y: 10478016.378614787, spatialReference: Object}
geometry.getCentroid()
Object {type: "point", x: -18090547.842482734, y: 10478016.37861477, spatialReference: Object}

How can i proceed with distance function.Sorry i am new to esri map? Can you please clarify this too?

0 Kudos
Nicholas-Furness
Esri Regular Contributor

No problem . The following should get you the radius in meters:

var radius = geometryEngine.distance(geometry.getCentroid(),geometry.getPoint(0,0),"meters");
0 Kudos
FancyAugustin
New Contributor II

When i try to add 

esri/geometry/geometryEngine 

under require in the which i posted before ,it is giving me error saying  

Uncaught ReferenceError: require is not defined

Can i get your help on this?

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Probably best to post a question like that over on the ArcGIS API for JavaScript space. But if your previous require statement worked, this will work too. Since you're getting started with the APIs, perhaps take a look at the Develop sections of the DevLabs and Hackerlabs (including the 3.x labs).

0 Kudos
FancyAugustin
New Contributor II

Really sorry that was issue in network.

radius:1927212.6012732424

The above radius i got when executed that code.

But is this valid value,i doubt that?

0 Kudos