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

Rotate output #39

Closed fishcharlie closed 3 years ago

fishcharlie commented 3 years ago

Is there a way to rotate the output? Currently the output results in a diamond. Ideally I'd like to rotate it 45 degrees so that it represents a square as opposed to a diamond. The bearing option doesn't seem to do anything when I try to set that to 45.

fishcharlie commented 3 years ago

One thing I forgot to mention, this is when numberOfEdges is set to 4.

johachi commented 3 years ago

Hi @fishcharlie , I get the correct rotation. Are you sure you spelled it correctly?

Passing bearing: 45

Code:

circle([-105.0075602531433, 39.748670669322394], 100, { numberOfEdges: 4, bearing: 45 });
{
  type: "Polygon",
  coordinates: [
    [
      [-105.0067340774561, 39.74930587122309],
      [-105.00838642883049, 39.74930587122309],
      [-105.00838641359589, 39.748035461565095],
      [-105.00673409269072, 39.748035461565095],
      [-105.0067340774561, 39.74930587122309],
    ],
  ],
}

On map:

Rotated dimond

Omitting bearing

Code:

circle([-105.0075602531433, 39.748670669322394], 100, { numberOfEdges: 4 });
{
  type: "Polygon",
  coordinates: [
    [
      [-105.00756025314331, 39.74956898460652],
      [-105.00872863123237, 39.74867066346578],
      [-105.00756025314331, 39.74777235403828],
      [-105.00639187505423, 39.74867066346578],
      [-105.00756025314331, 39.74956898460652],
    ],
  ],
};

On map:

Screen Shot 2021-05-02 at 18 15 51
fishcharlie commented 3 years ago

@johachi The issue here was poor documentation. In the README it lists bearing as the 5th parameter. In reality, the function only accepts 3 parameters. The 3rd one being either a number representing numberOfEdges, OR an object.

Screen Shot 2021-05-04 at 12 23 16 PM

No where other than the source code itself is this made clear. Maybe it'd be a good idea to update the README to make it more clear?

johachi commented 3 years ago

Your right, it is a little bit unclear unless one reads the source code. I have fixed it now. https://github.com/gabzim/circle-to-polygon/pull/40

Please feel free to contribute if you think there are more things that can be improved in the documentation 😄