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

Categories

HOME
xml
microsoftgraph
oracle12c
hyperlink
developer-tools
eslint
linkedin
c99
apache-flink
telegram
forms
datastore
mjml
zend-framework
swt
fftw
knitr
alarm
spring-data-mongodb
dojo
big-o
pearson-correlation
google-admin-sdk
nstableheaderview
pkcs#11
barcode
joomla3.0
sendgrid-api-v3
openpyxl
heap
xcodebuild
filechannel
gkturnbasedmatch
cumulocity
dynamic-sql
dimensional-modeling
chargify
template-engine
git-extensions
connector
guzzle
easeljs
object-storage
beta
ckfinder
froala
definitelytyped
surveymonkey
has-and-belongs-to-many
handler
mql
dst
laravel-eloquent
android-sugarorm
code-snippets
card.io
keras-layer
joomla2.5
navigator
protein-database
comparison-operators
resolution
apriori
wc
double-click
openresty
proget
term
automapper-5
reportservice2010
singleinstance
arq
reshape
d3-force-directed
javafx-css
materialized-path-pattern
usart
microstation
scaffolding
dimension
jtwig
riot
kendo-upload
toast
character-replacement
decimalformat
gocql
lazybones
uncompress
snoop
node-serialport
uvc
dbaccess
packet-sniffers
structuremap3
deform
appserver
machine-instruction
psr-4
trdion2011
ignite-ui
template-deduction
grails-domain-class
matrix-inverse
android-framework
websphere-esb
breakout
font-awesome-4.0.0
panda3d
iboutlet
thttpd
apache-whirr
jdb
kqueue
stress
virtualpathprovider
relative
mysql-error-1205
umra
strsep
presentation-layer
hbm2java
sifr
build-environment
mathematical-notation
google-wave
dojo-dnd
wcf-proxy

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