0
$\begingroup$

This might be a really simple question, but how do you generate equally spaced points on a circle? I have looked here and here, have played around for ages - I am sure I am missing something very obvious :/ Here does it, but is there anything more straightforward?

Obviously

ParametricPlot[{Sin[x], Cos[x]}, {x, -π, π}]

plots it, and

cplot[m_] := g1 = (d = (q = 100;
  f = (lop = 
     Transpose[{Flatten[
        Reverse[
          Table[Gamma[y], {y, 0, q}]] /. {ComplexInfinity -> m}], 
       Flatten[Table[x^n, {n, 0, q}]]}];
    {#1*#2} & @@@ lop);
  Flatten[f];
  Total[f]);
sol = Solve[d == 0];
r = ListPlot[{{Re@x, Im@x} /. sol}, AspectRatio -> Automatic, 
  PlotStyle -> Black];
Show[r, Axes -> False, ImageSize -> 800]);
Show[cplot[#] & /@ Range[1]]

is a roots example, but was after something simpler.

$\endgroup$
8
  • 1
    $\begingroup$ Hint: Divide $[0, 2\pi)$ into $n$ equal segments... $\endgroup$
    – rm -rf
    Mar 25, 2014 at 23:14
  • $\begingroup$ I had worked that much out ... just have a Mathematica mental block :/ $\endgroup$
    – martin
    Mar 25, 2014 at 23:16
  • $\begingroup$ Many functions' roots do it - just wanted a nice simple way to do it :/ $\endgroup$
    – martin
    Mar 25, 2014 at 23:17
  • 2
    $\begingroup$ mathematica.stackexchange.com/q/44415/5478 ;0 $\endgroup$
    – Kuba
    Mar 25, 2014 at 23:52
  • 1
    $\begingroup$ @martin Re curling....Perhaps this could be modified: mathematica.stackexchange.com/questions/20004/… $\endgroup$
    – Michael E2
    Mar 25, 2014 at 23:58

2 Answers 2

1
$\begingroup$

Here is a rather general solution to your problem. It produces a list of the coordinates of n regularly spaced points on a circle centered at {cx, cy} with radius r, where the initial point is rotated counterclockwise from the x-axis by initθ radians (defaults to 0).

validNum = Except[_Complex, _?NumericQ];
regSpacedPts[center : {cx : validNum, cy : validNum : 0}, r : validNum, 
             n_Integer /; n > 0, initθ : validNum] :=
  Table[center + r {Cos[# + initθ], Sin[# + initθ]} &[N[ 2 π k/n]], {k, 0, n - 1}]

Here is an application.

With[{xy = {1/4., 3/2}, r = .5, n = 5, θ = 90 °}, 
  Graphics[{Circle[xy, r], 
            PointSize[Large], Point[regSpacedPts[xy, r, n, θ]], 
            Red, Point[xy]},
    PlotRange -> {{-1/4, 3/4}, {1, 2}},
    Frame -> True,
    PlotRangePadding -> .1]]

5-points

$\endgroup$
3
  • $\begingroup$ OK, this gives me loads of things to study - 'Chop, With` and Except I am still unsure of - will give them a go - again - many thanks. $\endgroup$
    – martin
    Mar 26, 2014 at 0:24
  • $\begingroup$ @martin. Chop is a bit of fussiness on my part. You could probably remove it without any harm. The validNum pattern uses Except to exclude complex numbers from being used as arguments. $\endgroup$
    – m_goldberg
    Mar 26, 2014 at 0:29
  • 1
    $\begingroup$ @martin. I made some corrections you will want to attend to. I removed Chop (really not needed) and I stopped an extra copy of first point from being generated. This code was taken from some code It wrote to generate regular polygons, which used the extra point to close the polygon, something not needed for your application. $\endgroup$
    – m_goldberg
    Mar 26, 2014 at 0:45
1
$\begingroup$

Using ListPolarPlot you can do the following:

r = 1;
points = 6;
angle = 2 π / points;
Show[
    ParametricPlot[{r * Sin[x], r * Cos[x]}, {x, -π, π}],
    ListPolarPlot[Table[{angle * n, r}, {n, 1, points}], PlotStyle->{Black, PointSize[Large]}]
]
$\endgroup$
3
  • $\begingroup$ Great - thank you! I'm sure I will be kicking myself in a minute :/ $\endgroup$
    – martin
    Mar 25, 2014 at 23:18
  • $\begingroup$ ListPolarPlot - Great! :) $\endgroup$
    – martin
    Mar 25, 2014 at 23:19
  • $\begingroup$ Is there any way of converting these points to data that a regular ListPlot can plot? $\endgroup$
    – martin
    Mar 25, 2014 at 23:38

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