### 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).

### Related Links

Covering n points with three squares of minimum length

Double Linked List Insertion in Between

How to optimally partition a list of numbers (even in length) so that both halves are positive? [closed]

What is the fastest way to compute the F-score for a million annotations?

What is the quickest method of matrix multiplication?

Decompose and process time series in binary matrix

Polynomial in n code? what does it mean [duplicate]

Simple weighted rating value

Finding shortest path between pass through a specific vertex

Resource Allocation in a Wireless Network

Given a set of ranges S, and an overlapping range R, find the smallest subset in S that encompases R

Effective algorithm for finding out if oriented graph is unilaterally connected?

what is exactly the reason of halting

Waiting time and turn around time in scheduling algorithm

2 variable non linear search algorithm

Distance between two nodes in a tree weighted