In code form, the calculation of the coordinates of the polar rose point in the Cartesian system can be represented as follows:
X := OriginX + A * Cos(K * Theta) * Cos(Theta);
Y := OriginY + A * Cos(K * Theta) * Sin(Theta);
| Parameter | Meaning |
|---|---|
OriginX |
the X coordinate of the rose's center point |
OriginY |
the Y coordinate of the rose's center point |
A |
target rose radius |
K |
angular frequency |
The above code works prefectly. For example, setting K as 5, I get a flower with five petals. For other positive integer values of K I also get correct flowers, consistent with the first row of those given on Wikipedia:

Image credit: Jason Davies via Wikimedia Commons.
Now I would like my code to be able to generate roses from other rows. I found the article Polar rose garden and there is a image with various roses, where k is integer or real:
https://blog.k2h.se/post/2020-01-03-polar-rose-garden_files/figure-html/unnamed-chunk-2-1.png
For example, for k = 1 / 3, the rose should look like this:
Also https://blog.k2h.se/post/2020-01-03-polar-rose-garden_files/figure-html/unnamed-chunk-2-1.png look for caption 1/3.
but if I use the following code:
var
Theta: Single;
OriginX: Integer;
OriginY: Integer;
Size: Integer;
X: Integer;
Y: Integer;
K: Single;
begin
OriginX := 120;
OriginY := 120;
Size := 120;
K := 1 / 3;
Theta := 0.0;
while Theta < Pi * 2 do
begin
X := Round(OriginX + Size * Cos(K * Theta) * Cos(Theta));
Y := Round(OriginY + Size * Cos(K * Theta) * Sin(Theta));
Canvas.Pixels[X, Y] := clGray;
Theta += 0.001;
end;
end;
the rose looks like this:
Could anyone advise why my graph is broken?
PS: I'm not a mathematician, so C/Pascal code would be perfect.

We can't just blindly run from 0 to 2PI, because that doesn't guarantee a full period of the graph. After all, we're not working with
cos(theta)andsin(theta), we're working with an additional factorcos(n/d * theta), so we'll need to at the very least multiply by d in order to get back to full periods, but n is a bit sneaky here.If we turn to the Wikipedia page for rose curves, specifically the section for when k is rational, we learn that:
So a modulo-based check should do:
The last time I've used Pascal was probably 40 years ago, so you'll have to "port" that solution yourself, but that should be pretty easy =)