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.
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
plot equal– the same scale on both axes. Without it the graph would stretch to the width of the window and the circle would turn into an ellipse. (plot normalswitches back.)plot name 1, "r = cos(2φ)"– a series name in the legend and in the list of series, instead of “plot 1”, “plot 2”.plot 4, break– the next point of the series starts a new line. The task calls it after every sixth point of the circle, which produces a dashed line.
What's more, series can be created in any order – plot 3 before plot 1 is no longer a problem.
kk
and breaks in the line. The graph window's legend and list of series are named by the program.Try it yourself
- Install REMcalc 1.1 (Download; the Free edition is enough).
- In the Window → Expression Library menu, choose the My Formulas library and click New… with the BASIC task box checked.
- 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