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]

Categories

HOME
delphi-7
prism
developer-tools
fpga
rdbms
saml-2.0
oracle-apex-5
static-site
emscripten
babeljs
drop-down-menu
java.util.logging
project-intu
line
magnetic-cards
connector
drive
rubymotion
libigl
react-toolbox
epsilon
interpreter
expressionengine3
entity-relationship-model
linked-data
custom-controls
autodesk-designautomation
panoramas
record
sql-server-2000
least-squares
roblox
android-augmented-reality
projects-and-solutions
recurrent-neural-network
news
mcustomscrollbar
postgresql-8.4
drupal-theming
opencmis
openblas
static-cast
opengl-4
git-flow
shinobi
renaming
juice-ui
testrail
installshield-2010
delta
cifilter
gogs
shopping
project-organization
vhosts
dynamics-nav-2016
sciruby
poppler
sha512
fail2ban
umlgraph
linkedin-jsapi
kissfft
grails-domain-class
wxformbuilder
spring-remoting
dsym
accesscontrolexception
code-duplication
cffile
jquery-1.9
twisted.web
resource-management
pdfviewer
frameworkelementfactory
hibernateexception
box2d-iphone
procedures
promotion-code
u2netdk
automationelement
lr
umra
w3c-geolocation
django-paypal
commerceserver2007
uideviceorientation
addchild
fail-fast-fail-early
unmanagedresources
leader

Resources

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