0

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.

martin
  • 8,678
  • 4
  • 23
  • 70

2 Answers2

1

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]}]
]
Tyilo
  • 1,545
  • 13
  • 25
1

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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • OK, this gives me loads of things to study - 'Chop,WithandExcept` I am still unsure of - will give them a go - again - many thanks. – martin Mar 26 '14 at 00:24
  • @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. – m_goldberg Mar 26 '14 at 00:29
  • 1
    @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. – m_goldberg Mar 26 '14 at 00:45