gabzim / circle-to-polygon

Receives a Coordinate, a Radius and a Number of edges and aproximates a circle by creating a polygon that fills its area
ISC License
113 stars 29 forks source link

Circle to polygon returns oval/ellipse instead of a shape like circle #5

Closed greytexture closed 5 years ago

greytexture commented 6 years ago

I used following code to return a polygon which is approximately like a circle.

let coordinates = [28.612484207825005, 77.23574939044147]; 

let radius = 311;      

let numberOfEdges = 32;       

let polygon = circleToPolygon(coordinates, radius, numberOfEdges);

var coords = polygon.coordinates;

When I used coords and created a polygon shape using Google Maps JS API, it showed a shape like oval (2 ends were very far from each other, two very near, hope you understand).

In fact, the different in distances is approx. 4:1 ratio. So it's never a shape closer to circle.

Is there any issue, or is it supposed to do this intentionally?

valdenio commented 5 years ago

The same problem was happening to me. After a while, I figured it out that the coordinates must be in the format [lon, lat], not otherwise.

It is described in the readme as well and I hadn't noticed previously.

gabzim commented 5 years ago

Thanks for taking that @valdenio, the order of coordinates is very important, thank you. Maybe it should have been an object {lat, lon}, what do you think? @valdenio @vikaskumar2299, it seems less confusing I suppose.

valdenio commented 5 years ago

@gabzim I guess it would be more intuitive if it were {lat, lon}. In that case, the order of the returned coordinates should also be changed (currently it is {lon, lat} in the response too, right?).

gabzim commented 5 years ago

I mean it would be objects so key order wouldn't matter. The reason it's an array is because that's how most libraries deal with coordinates, [lon,lat], but it can be a little less intuitive for a programmer.