Created
January 10, 2013 03:04
-
-
Save lydonchandra/4499081 to your computer and use it in GitHub Desktop.
Calculate Radius of a Circle in OpenLayers.
Circle is implemented as a LinearRing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OpenLayers.Geometry.LinearRing.prototype.getRadius = function() { | |
//http://gis.stackexchange.com/questions/20982/how-to-get-the-radius-of-a-circle-in-openlayers | |
//Use the formula for the area of a regular polygon. | |
//With a radius of r and k vertices (where in practice k typically varies from 4 through 360), | |
//the area now is A = r^2 * k Sin(360 / k) / 2. Solving for r yields r = Sqrt(2 A / (k Sin(360/k))). | |
//For k = 40 that's r = 0.565352 * Sqrt(A). | |
var area = Math.abs( this.getArea() ); | |
var polygonSides = 100; | |
var radius = Math.sqrt( 2*area/(polygonSides*Math.sin(2*Math.PI/polygonSides)) ); | |
return radius; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment