# 2d rotation about an arbitrary point

Discussion in 'Homework Help' started by zulfi100, Mar 16, 2015.

1. ### zulfi100 Thread Starter Member

Jun 7, 2012
320
0
Hi,
I want to develop the eq of 2D rotation about an arbitrary point. Book has given this eq but it does not show how we got it:
Translation of Object to Origin:
x1 = x-xr
y1= y-yr

x' = x1 cosθ -y1 sinθ
y' = x1 sinθ + y1 cosθ

Putting values:
x' = (x-xr) cosθ - (y-yr) sinθ
y' = (x-xr) sinθ + (y-yr) cosθ

Translation of object back to its original position (xr, yr)

x'= xr + (x-xr) cosθ - (y-yr) sinθ
y' = yr +(x-xr) sinθ + (y-yr) cosθ

Some body please guide me whether my approach is correct or not?

Zulfi.

2. ### MrChips Moderator

Oct 2, 2009
12,636
3,455
Straightforward.

3. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
Well, since you've got the correct solution, how does your solution compare to it?

Jun 7, 2012
320
0
Hi,

Zulfi.

5. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
You said in your very first post that the book gives the equations, just not how they got them. So compare your results with the book's.

6. ### zulfi100 Thread Starter Member

Jun 7, 2012
320
0
Hi,
Both matched completely. That's where i stopped my derivation. I started with nothing and then i developed the idea how to reach to the book equation. Then i developed it but i thought i am making some mistake with my 'x1' and 'y1' variables. That's why i posted to confirm my approach. Thanks again.

Zulfi.

7. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
What mistake do you think you are making? Sure, it's possible that the book answer is wrong and that you happen to start from scratch and make the same mistake, but how likely is that? Test your results with some actual values and see if they work. Try points in different quadrants with positive and negative angles of rotation.

8. ### zulfi100 Thread Starter Member

Jun 7, 2012
320
0
Hi,
Thanks for your reply. Its a well known equation. It cant be wrong. I have even written a program for rotating geometrical objects using these eq. But you are right, negative values can create problems when we do drawing in xy plane using the computer program beacause i dont know how to draw in quadrants other the first. Do you have any idea for this??
If possible please provide me some specific examples how can say that this eq is wrong??
Zulfi.

Mar 31, 2012
18,087
4,917

10. ### MrAl Distinguished Member

Jun 17, 2014
2,562
518
Hi,

If you translate the object from (x,y) to (0,0), then rotate it about (0,0), then translate it back to (x,y) isnt hat good enough?
If you do this for an arbitrary point you may be able to reduce the formula, and then test it for several randomly generated points.
The best test is to use a group of points calling one point the center, then use your formula to rotate it at that point, then use your formula a second time with negative angle to rotate the group of points back to the original position. If your formula works then the original points should match the doubly rotated points within some error limit depending on the number precision you are using, so say to within about 1e-12 or better using standard 16 bit floating point.
So the entire process would go like this:
Starting with point set A:
Translate A to origin, rotate by angle TH, translate back to x,y. This generates point set B.
Translate B back to origin, rotate by angle -TH, translate back to x,y. This generates point set C.
Test points A vs points B, then should match within some small error limit such as 1e-12.

If you create a formula to get from A to B, then use the same formula to get from B to C, you may be able to combine the formulas into one closed form solution which translates both ways and therefore should end up with the same x,y where x and y are variables not actual points. This may or may not work, but you could try it. That would prove your formula in one shot without having to try a bunch of randomly generated points. For example the formula for C and A should satisfy:
A-C=e
where e is the error limit.

This closed form solution probably means inserting the formula for x and y into the second formula for x, then the formula for x and y into the second formula for y. The second formula has negative angle and the first has positive angle, or vice versa.

Lets see if we can look at this in functional form...

x1=f1x(x0,y0)
y1=f1y(x0,y0)

x2=f2x(x1,y1)
y2=f2y(x1,y1)

which combined looks like:
x2=f2x(f1x(x0,y0),f1y(x0,y0))
y2=f2y(f1x(x0,y0),f1y(x0,y0))

and so:
f2x(f1x(x0,y0),f1y(x0,y0))-x0=0
f2y(f1x(x0,y0),f1y(x0,y0))-y0=0

if the formulas are correct, although because of the calculation there maybe a small error rather than zero (but see below). You should still test a few actual points though too.

Of course you can create other closed form tests too, such as rotating the point by some angle like 360/N, then rotate it N times, then check for equality again, although this means reinserting solutions more than one time if N is greater than 2.
Another example would be to rotate by say N degrees, then rotate again by 360-N degrees, then test for equality.

Here is an example using the plus and minus angle technique:

Using the two formulas:
x1=xr+(x-xr)*cos(TH)-(y-yr)*sin(TH)
y1=yr+(x-xr)*sin(TH)+(y-yr)*cos(TH)