1

I want to create an illustrator script that places dots around a circle.

Let's say the shells are given, but I need a way to evenly spread out a n amount of dots (electrons) on a n-sized circle. For example 2 dots on the first circle, 8 on the second, etc.

Here is an example

To rephrase my problem: I have up to 7 circles that are all set. How do I spread out the dots on those circles?

Tim M.
  • 53,671
  • 14
  • 120
  • 163
SHDY
  • 33
  • 1
  • 4

2 Answers2

6

Since the whole circle is 2 * PI radians, circle center is at (0, 0) and suppose you have n dots, you have to place the i'th dot on coordinate x = R * cos(i * 2 * PI / n) and y = R * sin(i * 2 * PI / n) for i = 0..n-1 where R is the radius of current circle.

This is all about Polar coordinate system

dreamzor
  • 5,795
  • 4
  • 41
  • 61
  • 2
    Check your maths - this would place at angles +∞, 2π, π, 2π/3, π/2, - it should by `2πi/n` not `2π/i` – Pete Kirkham Oct 05 '12 at 10:29
  • 1
    This answer is wrong - it will place dots more DENSLY near the center of the circle. You shouldn't consider "random polar coordinate" when "even" distribution is required. – enigmatoP Mar 06 '14 at 08:37
  • @enigmatoP indeed, corrected the obvious mistake, thanks. – dreamzor Jul 18 '15 at 16:38
0
for(i =0; i < 60; i++){aDot=document.getElementsByTagName('div')[i];aDot.style.top = sin(i+43/9.4)*120+180;aDot.style.left= cos(i+43/9.4)*120+400;}

try it here

Live example of full functioning circle

  • You're code as is very hard to read due to missing line breaks. Please format the code properly to include line breaks between statements. – Jonathon S. Aug 01 '22 at 12:47
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/32368326) – mymiracl Aug 03 '22 at 12:43