Ok, I plotted every function. I can see where you were going with this through I don't understand it yet completely. Maybe I'll get to it later.
@swiftcoder mentioned that you are using mod() to wrap the function back to desired range but you were not converting it to radians in the first place so I'm left a bit confused. I see that you had to bring it back because of +2 (+M*.5) but it's still not entirely clear to me.
It came to my mind that when I tried to convert [0, 4] to [0, 6.28] radians I can do it with percentages too. If we say that the first part is in domain K and second in domain L, then if we have some angle A_k in domain K, we can divide it by K Lenght, that is 4. This will give us the percentage p. If we multiply L Lenght * p it will give us the same angle in domain L, that is a angle A_l in radians.
Now, I know that the next calculation is wrong, but I guess that we could do something like we did before to get the same answer, try to multiply A_k * 6.28 and mod() this with K/L Lenght. This doesn't give us A_l but I'm sure that we could do something similar to arrive to it?