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:


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]};
randomCirclePoints[n_, center_, radius_] := Block[{z},
   z /. NSolve[(Exp[I RandomReal[{0, 2 Pi}]] (z - {1, I}.center))^n ==
       radius^n, z]

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

Mathematica graphics

| improve this answer | |
  • 2
    $\begingroup$ f[center_, radius_, n_] := Graphics[Point@({Re@#, Im@#} + center & /@ (radius E^(I 2 Pi Range@n/n))), Frame -> True] :) $\endgroup$ – Dr. belisarius Mar 21 '14 at 4:26
  • $\begingroup$ @MichaelE2 fun is healthy...nice+1 :) $\endgroup$ – ubpdqn Mar 21 '14 at 4:39
func[cntr_, rad_, n_, ang0_] := 
 Graphics[{Circle[cntr, rad], {Red, PointSize@0.02, 
    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.

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

enter image description here

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

| improve this answer | |
  • $\begingroup$ 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}]. $\endgroup$ – Pavithran Iyer Mar 21 '14 at 3:50
  • $\begingroup$ @PavithranIyer yes this essentially the same (see the argument of the function Point in the function above. $\endgroup$ – ubpdqn Mar 21 '14 at 3:53
  • 1
    $\begingroup$ @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. $\endgroup$ – user484 Mar 21 '14 at 18:20
  • $\begingroup$ @RahulNarain...I didn't pause to check... $\endgroup$ – ubpdqn Mar 22 '14 at 1:33
  • $\begingroup$ Thanks to all. All answers are great. I am allowed to mark only one. $\endgroup$ – 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}]}]

enter image description here

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}]]
| improve this answer | |

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]}]

Mathematica graphics

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.

| improve this answer | |

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]]]
| improve this answer | |

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_] := 
          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]

enter image description here

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).

| improve this answer | |
  • 2
    $\begingroup$ I don't know about "natural", this solution requires paying $50 to obtain that package. Mathematica is already not cheap. $\endgroup$ – RunnyKine Mar 21 '14 at 20:18
  • $\begingroup$ 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. $\endgroup$ – murray Mar 21 '14 at 21:44
  • $\begingroup$ Actually, there's a free version of Presentations that omits the documentation and palettes. $\endgroup$ – murray Oct 18 '15 at 18:46

Another simple routine:

myCircle[cent_?VectorQ, r_?Positive, n_Integer] := 
         AffineTransform[{DiagonalMatrix[{r, r}], cent}][CirclePoints[n]]

Using lalmei's example:

Graphics[{Yellow, Point[myCircle[{0, 0}, 1, 12]],
          Black, Point[myCircle[{1, 1}, 1, 12]],
          Green, Point[myCircle[{2, 0}, 1, 12]],
          Red, Point[myCircle[{3, 1}, 1/5, 12]],
          Blue, Point[myCircle[{-1, 1}, 1, 12]]}]

equispaced points on various circles

Adding a phase is easy, too:

myCircle[cent_?VectorQ, r_?Positive, ph_?NumericQ, n_Integer] := 
         AffineTransform[{DiagonalMatrix[{r, r}].RotationMatrix[ph], cent}] @ 

(CirclePoints[] is new in version 10.1.)

Pickett mentions that CirclePoints[] actually supports a more extensive syntax, one that I missed in the first reading of the docs: CirclePoints[cent, {r, ph}, n].

Thus, one can redo the first example as

Graphics[{Yellow, Point[CirclePoints[{0, 0}, 1, 12]],
          Black, Point[CirclePoints[{1, 1}, 1, 12]],
          Green, Point[CirclePoints[{2, 0}, 1, 12]],
          Red, Point[CirclePoints[{3, 1}, 1/5, 12]],
          Blue, Point[CirclePoints[{-1, 1}, 1, 12]]}]
| improve this answer | |
  • 2
    $\begingroup$ As I understand it, this is a reimplementation of CirclePoints[{x,y}, {r, theta}, n] relying only on CirclePoints[n]. $\endgroup$ – C. E. Oct 18 '15 at 14:34
  • $\begingroup$ Missed that usage! Thanks @Pickett. $\endgroup$ – J. M.'s discontentment Oct 18 '15 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.