Polar Roses: A Graph Straight from the Task

The curve r = cos(kφ) draws a flower: for odd k it has k petals, for even k it has 2k. In REMcalc 1.1 the task itself sets the same scale on both axes, names the series in the legend and even draws a dashed line – the graph is ready as soon as the program finishes.

Video: three polar roses and a dashed circle being drawn in the graph window
Video: polar roses 0:09 – roses with 4, 3 and 5 petals and a dashed unit circle are drawn at the same time; the legend is named from the very first point.

From polar coordinates to the graph

A point in polar coordinates has a distance r from the origin and an angle φ. It is converted to the graph's Cartesian coordinates as

x = r · cos φ,    y = r · sin φ,    here r = cos(k · φ)

For k = 3 and 5 you get 3 and 5 petals: as φ goes from 0 to 2π, the curve is traced twice, and the second pass lands exactly on the first. For k = 2, r is negative in half of the petals, the point “flips” over to the opposite side, and there are 4 petals. The task keeps the values of k in an array with initial values, dim kk = (2; 3; 5), and draws all three roses in a single loop.

Three new graph features

What's more, series can be created in any order – plot 3 before plot 1 is no longer a problem.

The polar roses program next to the graph window with a legend
Program and result. 20 lines: series names, the same scale on both axes, the array kk and breaks in the line. The graph window's legend and list of series are named by the program.

Try it yourself

  1. Install REMcalc 1.1 (Download; the Free edition is enough).
  2. In the Window → Expression Library menu, choose the My Formulas library and click New… with the BASIC task box checked.
  3. Paste the program and run it. Try other values of k in the array kk – for example (4; 7; 1.5). For a non-integer k the curve does not close after one turn; extend the loop (for j=0 to 960) and see how many turns it needs.

Comments and variable names in the program are in Czech.

' Polární růže r = cos(k·φ) v grafu: stejné měřítko os, názvy řad v legendě,
' čárkovaná kružnice přerušováním čáry (plot n, break)
mode rad
plot equal
plot name 1, "r = cos(2φ)"
plot name 2, "r = cos(3φ)"
plot name 3, "r = cos(5φ)"
plot name 4, "kružnice r = 1 (čárkovaně)"
dim kk = (2; 3; 5)
for j=0 to 240
  f = j*pi/120
  for s=1 to 3
    r = cos(kk(s)*f)
    plot s, r*cos(f), r*sin(f)
  next
  plot 4, cos(f), sin(f)
  if j mod 6 = 5 then plot 4, break
  delay 25
next
delay 1500