rotating a rectangle around its center?
              in 
             Programming Questions 
              •  
              4 months ago    
            
 
           I want to click and drag a corner of a rectangle, and have the rectangle spin around its center.
This is pretty easy to do with a square:
rot = PI * 3 / 4 + atan2( (centerY - mouseY), (centerX - mouseX) ); 
            But if I want to rotate a rectangle, I am not sure how to handle the offset to make the rotation smooth as the mouse is moved.
In this jsfiddle example, http://jsfiddle.net/R4QpV/, clicking on the red corner lets you rotate around the center of the square. But what if you click on the green corner, there is a jump. How to make dragging the green corner smooth and follow the mouse as it does when clicking the square's corner?
 
              
              1  
            
 
            