### algorithm

#### rotating a rectangle around its center?

```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?
```
`With a square, the diagonal is along the angle PI / 4 (or 3*PI/4) as you have it. With a rectangle, you need to set the rotation based on the angle of the diagonal. I'm not sure exactly what your coordinate system is, but you should replace PI * 3 / 4 with something like atan2(centerY - cornerY, centerX - cornerX) (give or take a +/- sign).`

### Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization