# Choosing $n$ equidistant points on a circle with given radius and center

I would like to have a function circle which takes two inputs: a tuple {x,y} and a real number r and outputs the cooridinates of points on the circumference of a circle that is centered at $(x,y)$ which has radius $r$.

Importantly, I want the points to be equidistant on the circle.

I tried to implement the procedure here described as Circle Point Picking. But I don't get equidistant points.

Kindly help me. Here is the code I tried:

num = 20; r = 50;
circle = Module[{},
random = RandomReal[{-2, 2}, {num + 10, 2}];
random = Take[DeleteCases[random, #1^2 + #2^2 >= r^2 &], num];
Table[r {(x[[1]]^2 - x[[2]]^2)/(x[[1]]^2 + x[[2]]^2),
2 x[[1]] x[[2]]/(x[[1]]^2 + x[[2]]^2)}, {x, random}]
]


The above code will output num=20 points on a circle that are not equidistant on the circumference. Here is the output represented as a ListPlot:

ListPlot[circle]


Irrelevant as such for the question, but if anyone is curious:

The context for getting equidistant points is that I want to embed a graph with some vertices located on the points. If you instead know how to do this, kindly tell me. I cannot find a use for CircularEmbedding because I only want a circular embedding on some vertices of the graph, not all vertices. The only way I see is to explicitly give the vertex cooridinates as points on a circle.

-

Just for fun:

SetAttributes[parts, Listable];
parts[z_] := {Re[z], Im[z]};
parts[
z /. NSolve[(Exp[I RandomReal[{0, 2 Pi}]] (z - {1, I}.center))^n ==
]
]

Graphics[
{Red, Point@randomCirclePoints[33, {2.5, 1}, 4]},
Frame -> True]


-
f[center_, radius_, n_] := Graphics[Point@({Re@#, Im@#} + center & /@ (radius E^(I 2 Pi Range@n/n))), Frame -> True] :) –  belisarius Mar 21 '14 at 4:26
@MichaelE2 fun is healthy...nice+1 :) –  ubpdqn Mar 21 '14 at 4:39
func[cntr_, rad_, n_, ang0_] :=
Point[Table[rad{Cos [ang0 + j],Sin[ang0 + j]}, {j, 0,
2 Pi - 2 Pi/n, 2 Pi/n}]]}}]


Here cntr is centre of circle, rad is radius, n is the number of points/segments, ang0 is just specifying where to start.

Manipulate[
func[{0, 0}, 1, num, a], {{num, 3}, Range[3, 20]}, {a, 0, 2 Pi}]


You could randomize your starting position. Apologies, if have misunderstood the intent.

-
Thank you for the illustrative suggestion. I also found a simple solution: circle = Table[{r Cos[2 \[Pi]/num *(i - 1)], r Sin[2 \[Pi]/num *(i - 1)]}, {i, 1, num + 1}]. –  Pavithran Iyer Mar 21 '14 at 3:50
@PavithranIyer yes this essentially the same (see the argument of the function Point in the function above. –  ubpdqn Mar 21 '14 at 3:53
@Pavithran Your code creates $n+1$ points of which the first and last are the same. I'm not sure that's what you want. –  Rahul Mar 21 '14 at 18:20
@RahulNarain...I didn't pause to check... –  ubpdqn Mar 22 '14 at 1:33
Thanks to all. All answers are great. I am allowed to mark only one. –  Pavithran Iyer Mar 24 '14 at 23:12

Here is a simple one, p sets how many points you want, q the radius and point the position of the center

 mycircle[p_, q_, point_:{0,0}] := Table[{q Cos[2 Pi k /p], q Sin[2 Pi k /p]} + point, {k, p}]

Graphics[{Yellow, Point /@ mycircle[12, 1], Black,
Point /@ mycircle[12, 1, {1, 1}], Green,
Point /@ mycircle[12, 1, {2, 0}], Red,
Point /@ mycircle[12, 0.2, {3, 1}], Blue,
Point /@ mycircle[12, 1, {-1, 1}]}]


The randomness then it is just a random phase to the points

 mycirclerd[p_, q_, point_: {0, 0}] :=
Module[{phase = RandomReal[{0, 2 Pi}]},
Table[{q Cos[2 Pi k /p + phase], q Sin[2 Pi k /p + phase]} + point, {k, p}]]

-

Here is a quick and dirty (read approximate) way to achieve this using Version 10 capabilities:

circ[ctr_, r_, n_] := MeshCoordinates @ DiscretizeRegion[Circle[ctr, r],
MaxCellMeasure -> {"Length" -> 2 Pi r /(n - 1.5)}]


Here ctr is the center, r, the radius and n number of points.

Visualize (for $n = 5$):

Graphics[{Red, PointSize[0.02], Point@circ[{0, 0}, 3, 5], Blue, Circle[{0, 0}, 3]}]


Note: You'll have to tweak that number 1.5 in the denominator of "Length" definition in the MaxCellMeasure option to get the right number of points. Ideally it should just be $2\pi r/n$, but that doesn't always give the desired $n$. At least, it does produce equidistant points on the circle.

-

As you didn't specify that any randomness was required, the natural solution to your problem for $n$ points and circle of radius $r$ is to find the $n$ complex $n$th roots of $r$, then translate them by the complex number $z = (x, y)$.

To implement that, a "natural" thing is to use David Park's Presentations add-on (http://home.comcast.net/~djmpark/DrawGraphicsPage.html), which allows you to work directly with complex numbers instead of having to use trig functions:

<< Presentations

circlePoints[ctr_, r_, n_] :=
Draw2D[{
ComplexCirclePoint[#, 4, Black, Orange] & /@ (ctr + r Exp[Range[n] 2 Pi I/n]),
Legacy@DarkGreen, ComplexCircle[ctr, r]
},
Axes -> True, Background -> Legacy@Linen, ImageSize -> 200]


For example:

circlePoints[0.5 + 0.75 I, 3, 12]


Should you wish randomness, you could include a random rotation (implemented as a complex multiplication or, equivalently, an addition of phase in the argument in the exponential).

-
I don't know about "natural", this solution requires paying $50 to obtain that package. Mathematica is already not cheap. – RunnyKine Mar 21 '14 at 20:18 The point is that, despite Mathematica wanting to do calculations as complex numbers (so that one often has to specify the domain is the reals), when it comes to 2D graphics, plain Mathematica forces one to take the artificial step of separating complex numbers into real and imaginary parts. – murray Mar 21 '14 at 21:44 One compact way to get$n\$ points on a circle would be

CirclePoints[center_,radius_,n_] := (center+radius #&) /@
Transpose @ Through[{Re,Im}[Exp[2\[Pi] I Range[n]/n]]]
`
-