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

Stroke width transform alternative

Building Red-Black Tree from sorted array in linear time

complexity algorithm recurrence relation

golang multiplication algorithm in html template

3D mesh edge detection / feature line computation algorithm

Functional Programming Idiom to compute maximum of 4 numbers without mutation in racket/haskell

Count nodes bigger then root in each subtree of a given binary tree in O(n log n)

Lossless compression of an ordered series of 29 digits (each 0 to 5 Likert scale)

How to find the value for a given key if a hash function is chosen randomly from Universal family of hash functions?

Can anyone explain what this algorithm does?

What is the difference between gradient and imgradient?

Substring comparison

Algorithm for joining circles into a polygon

Solving recurrence equations with fractions using Recursion Tree Method

How exactly does a Max 2 Sat reduce to a 3 Sat?

Why is this simple O(n) Haskell algorithm behaving more like O(2^n)? [duplicate]