Calculate end rotation drawing circles I have one circle, which grows and shrinks by manipulating the radius in a loop. 
While growing and shrinking, I draw a point on that circle. And within the same loop, increasing the angle for a next point.
originally it's written in JS, but I guess the math /theory will be the same
The setup is like this:


*

*radius = 0;

*circleAngle = 0;

*radiusAngle = 0;

*speed = 0.02;

*radiusSpeed = 4;

*circleSpeed = 2;


Within the loop, I update the angle for both the circle and the drawing line:
radius = Math.cos(radiusAngle) * 100;

// creating new point for line  
let pointOnCircle = {
    x: Math.cos(circleAngle) * radius,
    y: Math.sin(circleAngle) * radius
};

circleAngle += speed * circleSpeed;
radiusAngle += speed * radiusSpeed;

Within this same loop, I draw the circle with radius as the radius. And draw a point with x and y position of pointOnCircle.x and pointOnCircle.y
Now, after unknown times of rotation, the drawing line is back to where it started, closing the path perfectly. And depending on the settings, some type of pattern / flower thing is drawn. This unknown times of rotations is what I want to calculate. 
A working example can be found here: http://codepen.io/anon/pen/RGKOjP 
While playing with the variables radiusSpeed and circleSpeed I logged the angles and checked when the line was back at the beginning again. 
The results are as following. Where the first number is the variable radiusSpeed, the second is circleSpeed. The results are radiusAngle and circleAngle in degrees, at the moment the line comes back to its beginning:


*

*1, 1: 180, 180

*1, 2: 360, 720

*1, 3: 180, 540

*1, 4: 360, 1440

*1, 5: 180, 900

*2, 1: 720, 360

*2, 2: 180, 180

*2, 3: 720, 1080

*2, 4: 360, 720

*2, 5: 720, 1800

*3, 1: 540, 180

*3, 2: 1080, 720

*3, 3: 180, 180

*3, 4: 1080, 1440

*3, 5: 540, 900


I would like to calculate the rotations needed for the line to come back at the beginning and closing the path. 
There clearly is a pattern in the outcome. But I can't figure it out.
 A: You’ve got a curve given in polar coordinates $(r,\theta)$, where $r$ and $\theta$ are both periodic functions of some parameter $t$. To reduce clutter, let’s take the maximum radius to be $1$ instead of $100$, since that’s not going to change when or how often the curve returns to its starting point, which will then be $r=1$ and $\theta=0$.  
The polar angle $\theta$ is just swept out at a constant rate: $$\theta(t)=\omega_1t\tag{1}$$ where $\omega_1=$speed * circleSpeed. We also have the radiusAngle being swept out at a (possibly different) constant rate: $\phi(t)=\omega_2t$, with $\omega_2=$speed * radiusSpeed. The radius thus varies sinusoidally: $$r=\cos{\phi(t)}=\cos{\omega_2t}.\tag{2}$$ Eliminating $t$ from these equations gives $$r=\cos{{\omega_2\over\omega_1}\theta}.\tag{3}$$  
For this to represent the same point as the starting point, we must have $\theta=2n\pi$ ($n\in\mathbb Z$) and $r=1$, or, since $r$ can be negative, $\theta=(2n+1)\pi$ and $r=-1$. Plugging the first condition into (3), we get $$\cos\left({2{\omega_2\over\omega_1}n\pi}\right)=1 \\ 2{\omega_2\over\omega_1}n\pi = 2m\pi \\ {\omega_2\over\omega_1}n = m$$ for some integers $m$ and $n$. This can only hold if the ratio $\omega_2/\omega_1=$radiusSpeed / circleSpeed is rational, which it is in all of the cases that you tried. If we express this ratio in lowest terms as $p/q$, we get $pn=qm$, so we can find the smallest positive $n$ and $m$ for which this holds by computing the LCM of $p$ and $q$.  
Turning to the second possibility, $$\cos{\left({\omega_2\over\omega_1}(2n+1)\pi\right)}=-1 \\ {\omega_2\over\omega_1}(2n+1)\pi=(2m+1)\pi \\ {\omega_2\over\omega_1}(2n+1)=2m+1.$$ As before, we can rewrite this as $p(2n+1)=q(2m+1)$, which is similar to the previous equation except that both factors have to be odd.  
So, to find the recurrence angles $\theta$ and $\phi$, start by expressing radiusSpeed / circleSpeed in lowest terms as $p/q$ and find the LCM of the numerator and denominator. Divide this number by $p$ and $q$, respectively, to get the values $a$ and $b$. If these two numbers are both odd, then $\theta=\pi a$ and $\phi=\pi b$, otherwise $\theta=2\pi a$ and $\phi=2\pi b$.  
As a sanity check on this formula, we can see that it is consistent with some of the patterns in your data: the results are symmetric, in that swapping the two speeds also swaps the angles; all of the cases in which the two speeds are equal have the same angles; and cases 1,2 and 2,4 also have the same angles.
