Solved

Calculate new position of rotated rectangle

Posted on 2011-03-11
7
347 Views
Last Modified: 2012-05-11
I have a rotated rectangle that has an original location defined by the points O1,O2,O3,O4.
shaperotation-post-1.gif

Point O1 remains stationary as I drag point O3 to a new location, N3.
shaperotation-post.gif

How do I calculate the new locations of points N2 and N4?

Thanks!
0
Comment
Question by:sachelis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 33

Expert Comment

by:Paul Sauvé
ID: 35113500
HINT: The length of the perimeter remains constant:

O1O2 + O2O3 + O3O4 + O4O1 = O1N2 + N2N3 + N3N4 + N4O1

0
 

Author Comment

by:sachelis
ID: 35113656
"The length of the perimeter remains constant"? Huh? Point N3 can be dragged anywhere, so the length of the perimeter can change significantly. In my example images, the perimeter remained reasonably constant, but that's only happenstance.
0
 
LVL 33

Expert Comment

by:Paul Sauvé
ID: 35113794
Well, in that case:

O1N2 = N3N4
O1N4 = N2N3

otherwise it won't remain rectangular
0
Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

 
LVL 32

Expert Comment

by:phoffric
ID: 35114334
True that opposite sides are constrained to be equal; but to be rectangular, must also constrain angles to be 90 degress (otherwise you may end up with a parallelogram).

Translate the top rectangle linearly so that O1 -> (0,0). Then after some changes, translate the new rectangle back to O1's original position.

With that linear translation understanding, we can assume that O1 is at (0,0). Now you can treat O2, O3, and O4 as vectors in the plane.

Define unit vectors, u1 and u2:
u1 = O2/|O2|, where |O2| is the length of O2
u2 = O4/|O4|

Notice that O2 is the projection of O3 onto the line defined by b*u1 where b is some constant.
Notice that N2 is the projection of N3 onto the line defined by  c*u1 where c is some constant.

Since u1 and u2 form an orthonormal basis in the plane, then the projection is related by
|N2| = N3 .* u1   where .* is the dot product between N3 and u1
        http://en.wikipedia.org/wiki/Dot_product
After calculating |N2|, then N2 = |N2| u1

Similarly, compute N4.

Translate 4 points linearly back to original O1 and you have the coordinates.


0
 
LVL 1

Expert Comment

by:resvictory
ID: 35114891
There is a simple solution for your question.  Notice that  vectors

O1 N2 =   a O1 O2
O1 N4 =   b O1 O3

Your problem is solved, if you can find  "a" and "b". The only constraint  is that

O1 N2   - O1 N4 = O1 N3

It is equivalent to

a O1 O2 - b O1 N4 = O1 N3

This give you a system of two equations of  "a" and "b" corresponding to x and y coordinates.

a [O2(x) - O1(x)] - b [ N4(x) - O1(x)] = N3(x) - O1(x)
a [O2(y) - O1(y)] - b [ N4(y) - O1(y)] = N3(y) - O1(y)

You can solve the system of equations using Cramer's rule.
http://en.wikipedia.org/wiki/System_of_linear_equations

Hope it helps!
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35115266
In previous post, I wrote:
Since u1 and u2 form an orthonormal basis in the plane, then the projection is related by
|N2| = N3 .* u1   where .* is the dot product between N3 and u1
If you can move N3 to the left of O4, for example, then the dot product of N3 and u1 can be negative number.

So, to be more general allowing for any N3, then to get the coordinates of N2, you simply say:
      N2 = (N3 .* u1) u1
Now, the ± signs take care of themselves.
(Again, as mentioned earlier, we first translated the system where O1 is the origin).
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 500 total points
ID: 35117032
I noticed no one used basic trig to solve this, which seems odd.
imageThe angle from O4O1Y (which we'll call a) is cot(|O1.x-O4.x|/|O1.y-O4.y|)
The angle from xO1N3 (b) is cot(|O1.x-N3.x|/|O1.y-N3.y|)
The length O1N3 is sqrt((O1.x-N3.x)^2 + (O1.y-N3.y)^2)

The length O1N4 is cos(a+b)*O1N3
So N4.x is O1.x - sin(a)*O1N4
and N4.y is O1.y - cos(a)*O1N4

The length O1N2 is sin(a+b)*O1N3
So N2.x is O1.x + cos(a)*O1N2
and N2.y is O1.y - sin(a)*O1N2
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The greatest common divisor (gcd) of two positive integers is their largest common divisor. Let's consider two numbers 12 and 20. The divisors of 12 are 1, 2, 3, 4, 6, 12 The divisors of 20 are 1, 2, 4, 5, 10 20 The highest number among the c…
Prime numbers are natural numbers greater than 1 that have only two divisors (the number itself and 1). By “divisible” we mean dividend % divisor = 0 (% indicates MODULAR. It gives the reminder of a division operation). We’ll follow multiple approac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question