Search code examples
javascriptmathgeometrydraw2d-js

Draw circles around main circle in JavaScript with draw2d


In my application, I can draw circles with draw2d.js I'd like to know how I can draw circles around a main circle (here is lightblue).

I'd like to make it dynamically, because I could have more than 200 circles, so I need to calculate coords compared to the main circle.

But I need to avoid the red zone, I don't want to draw circles at 360°

Example below:

enter image description here


Solution

  • Let p be the center of the small circle, c the center of the main circle. Then a possible solution could look like

    p.x = c.x + R * Cos(Fi)
    p.y = c.y + R * Sin(Fi)
    

    Here R is distance, Fi is angle in allowed interval (for example -3*Pi/4..3*Pi/4)