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

Drawing a semi circle #50

Closed mosi6 closed 1 year ago

mosi6 commented 1 year ago

Hi! I need to be able to convert semi circles and quarter circles to geojson. I wonder if there’s any way to modify this script easily to accommodate for that. Thanks

johachi commented 1 year ago

It's actually relatively easy to do, just change

https://github.com/gabzim/circle-to-polygon/blob/d23c0ad86091be60c6f733ab43f2599c04393285/index.js#L41

to

 for (var i = 0; i <= n; ++i) {

and

https://github.com/gabzim/circle-to-polygon/blob/d23c0ad86091be60c6f733ab43f2599c04393285/index.js#L43-L45

to


 offset( 
   center, radius, earthRadius, start + (direction * Math.PI * -i) / n
 )

I have already tested and verified that this works.

Please let me know if you have any more questions or I will close this issue 🙂

mosi6 commented 1 year ago

This code only lets me draw semi circles(180 deg) specifically and I want a generic way to draw any angle(quarter circles and any other angle). I already kind of implemented it on my own but I did use the math from this project so thanks a lot for that.