How do I rotate a square around a circle? I have


*

*a circle of radius r

*a square of length l


The centre of the square is currently rotating around the circle in a path described by a circle of radius $(r + \frac{l}{2})$

However, the square overlaps the circle at e.g. 45°. I do not want the square to overlap with the circle at all, and still smoothly move around the circle. The square must not rotate, and should remain in contact with the circle i.e. the distance of the square from the circle should fluctuate as the square moves around the circle.
Is there a formula or algorithm for the path of the square?
[edit]
Thanks for all your help! I've implemented the movement based on Yves solution with help from Izaak's source code:

I drew a diagram to help me visualise the movement as well (the square moves along the red track):


Consider what happens when the square is directly to the right of the circle with the circle tangent to the midpoint of a side of the square. 
In order for the square to move up while remaining in contact without crossing into the square, it has to go straight up. 
This continues until the lower left vertex is on the circle, after which that vertex moves along the circle from the rightmost point to the topmost point. 
Then the square has to move straight left until the lower right vertex is on the circle, and then that vertex moves along the circle. 
Each time a vertex moves along the circle, the center of the square moves along a circular arc whose center is displaced from the center of the displayed circle. 
As a result, the center of the square moves straight up, then through a quarter circle arc, the straight left for the width of the square, then through another quarter circle, then down for the height of the square, etc. 
The total length of the path of the square's center until it returns to the start is
$2\pi r + 4s,$ where $r$ is the radius of the circle and $s$ is the side of the square. 
If you can use the distance along the path, not the direction between the centers, as your parameter for the motion of the square, it should make this easier to draw. 
