I'm having fun generating pretty pictures using math, and have started to draw rose curves. Thing is, I'm not sure when to stop drawing.
The formula is the same as from the wikipedia entry - a=angle, $k=n/d$, $r\cos(k*a)$, $x=r\cos a$, $y=r\sin a$. I'm working in degrees, so $a=0 to 359$, but that doesn't close all the curves, and only half of some...
I've read that periodicity is either $\pi d$ radians or $2\pi d$ radians, and the most accurate I've found so far is that if $n$ and $d$ are relatively prime, and both $n$ and $d$ are odd then it's $\pi d$ radians else $2\pi d$ radians. However, when testing I'm finding that's not the case.
For example, I store the first point and increase a until I get back to the first point's coordinates. I then print $n$,$d$ and final $a$ to the screen ($a$ is in degrees):
$(1,1) = 180$
$(1,2) = 720$
$(1,3) = 540$
$(1,4) = 1440$
$(1,5) = 900$
$(1,6) = 2160$
$(1,7) = 1260$
etc. I'm finding $n$ and $d$'s co-prime status by taking the GCD of $n$ and $d$ (I've also tried GCD$(n-1,d-1)$ to no avail). If it's $1$, and both $n$ and $d$ are odd, I then assume $\pi d$ radians else $2\pi d$ radians. The sequence matches my results above only for even values of $d$, and then only for certain values of $n$... I've tried allsorts of other methods and I'm afraid I'm just not getting it.
Is the original method I use (watching for a repeat of the first coordinate) the only way to accurately predict how many degrees it takes to start the next period?