## Help with understanding rotations

### Help with understanding rotations

Hi All,

I'm struggling to understand how the equations below are arrived at
for a rotation around the Z-axis:

x' = x cos theta - y sin theta
y' = etc...

This is how I understand it...

I have a point P in a 2D cartesian space that I want to rotate around
the origin to P'.

I know the values of P(x,y) and the angle of rotation (theta) and I
want to find the x,y co-ordinates of the new point P'.

Y
|
|  *P'
|    *P
|
|
|_______X

The x and y components of P form a triangle as do those of P'

P
/|
/ |
/  | Height = Py
/   |
/    |
/_____|
Base = Px

The hypotenuse (r) of the 'P triangle' above formed by the point P and
the origin is :

r = (Px^2 + Py^2)^0.5

So I now have the length of r which is the hypotenuse of my P and P'
triangles

Finding P'x
=============================

To find P'x i need one extra piece of information, either the length
of another side or an angle.

Using an angle - i need the angle between the x-axis and P'r (the
hypotenuse of P'):

to do this i need to:

1) Calculate the angle formed by my P triangle between the x-axis and
P r (the hypotenuse of P) - lets call this angle A

2) Add this angle to the known angle of rotation (A')

1 - I can calculate the angle A by doing the following:

tan(A) = Py/Px

so A = arctan(Py/Px)

2 - If i then add angle A to the angle of rotation (A') i get the
angle formed by my P' triangle between the x-axis and the hypotenuse
of P' which we will call angle A + A' so i can think about calculating
P'x as follows...

P'x = P'r * Cos(A + A')

Finally P'Y can be calculated using pythagoras's theorem or using sin
as follows

P'Y = P'r * sin(A + A')

so my question is how do I get from

x' = P'r * cos(A + A')
y' = P'r * sin(A + A')

to

x' = x cos(theta) - y sin theta etc...

Ben.

### Help with understanding rotations

>Hi All,

>I'm struggling to understand how the equations below are arrived at
>for a rotation around the Z-axis:

>x' = x cos theta - y sin theta
>y' = etc...

....

P      Q
|     /|
|    / |
|   /  |
|b /   |
| /a-b |
|______| X
O

Imagine this is a circle with point P and Q on the circle and O the
center.  The radius (length of OP and OQ) is r. The point P
corresponds to angle 'a' mesured counterclockwise from the X axis and
its cartesian coordinates are:

P: x1 = r*cos(a), y1 = r*sin(a), which can be rewritten as cos(a)=x1/r
and sin(a) = y1/r

If we rotate segment OP clockwise of an angle b, we get another angle
a-b corresponding to point Q. Its cartesian coordinates are

Q: x2 = r*cos(a-b), y2 = r*sin(a-b)

By using the trigonometric addition formulas we can rewrite these
coordinates as

x2 = r*[cos(a)*cos(b) + sin(a)*sin(b) ]

y2 = r*[sin(a)*cos(b) - cos(a)*sin(b) ]

But cos(a)=x1/r and sin(a) = y1/r so:

x2 = r*[ (x1/r)*cos(b) + (y1/r)*sin(b) ]
= x1*cos(b) + y1*sin(b)

y2 = r*[ (y1/r)*cos(b) - (x1/r)*sin(b) ]
= y1*cos(b) - x1*sin(b)

For a counter-clockwise rotation invert the signs in front of the
sin(b).

In 3D this corresponds to a rotation around the Z axis.

### Help with understanding rotations

Quote:>so my question is how do I get from

>x' = P'r * cos(A + A')
>y' = P'r * sin(A + A')

>to

>x' = x cos(theta) - y sin theta etc...

the length before rotation is

r = sqrt(x^2 + y^2)

and the length afterward is

r' = sqrt(x'^2 + y'^2)

However we also know r' = r! Furthermore we know

x = r cos(A)
y = r sin(A)

x' = r cos(A+A')
y' = r sin(A+A')

Trigonometry gives us a way to expand sums of angles. (Aha!)

cos(A+A') = cos(A)cos(A') - sin(A)sin(A')
sin(A+A') = sin(A)cos(A') + cos(A)sin(A')

Substitute.

x' = r cos(A+A')
= r cos(A)cos(A') - r sin(A)sin(A')
= x cos(A') - y sin(A')

y' = r sin(A+A')
= r sin(A)cos(A') + r cos(A)sin(A')
= y cos(A') + x sin(A')

Done.

### Help with understanding rotations

understand - just need to work through the proof for the expanding of
the sums of angles as this is new to me.

I was stumbling toward something but next time I'll try and write down
the facts and then use substitution like you did.

Cheers,
Ben.

> >so my question is how do I get from

> >x' = P'r * cos(A + A')
> >y' = P'r * sin(A + A')

> >to

> >x' = x cos(theta) - y sin theta etc...

> the length before rotation is

>   r = sqrt(x^2 + y^2)

> and the length afterward is

>   r' = sqrt(x'^2 + y'^2)

> However we also know r' = r! Furthermore we know

>   x = r cos(A)
>   y = r sin(A)

>   x' = r cos(A+A')
>   y' = r sin(A+A')

> Trigonometry gives us a way to expand sums of angles. (Aha!)

>   cos(A+A') = cos(A)cos(A') - sin(A)sin(A')
>   sin(A+A') = sin(A)cos(A') + cos(A)sin(A')

> Substitute.

>   x' = r cos(A+A')
>      = r cos(A)cos(A') - r sin(A)sin(A')
>      = x cos(A') - y sin(A')

>   y' = r sin(A+A')
>      = r sin(A)cos(A') + r cos(A)sin(A')
>      = y cos(A') + x sin(A')

> Done.

### Help with understanding rotations

>understand - just need to work through the proof for the expanding of
>the sums of angles as this is new to me.

I rather suspected that was a crucial missing piece for you, hence my
"Aha!" comment.

Here's another way to look at it. We are given a coordinate system in
which we have fixed x and y axes and coordinates with respect to those
axes. In other words, a certain amount of x and a certain amount of y
add up to r. Now suppose we rearrange our point of view to use a new
XY coordinate system in which r is pure X. In that new system we want

X' = cos(A')*r
Y' = sin(A')*r

to achieve rotation by angle A'. But now I want to introduce you to a
more powerful way to say this.

We will speak, not of mere coordinates, but of geometric objects that
are independent of coordinates. We will speak of vectors. So our given
coordinate system consists of two unit *vectors*, which I will call u
and v. And our given object to rotate is a *vector*, which I will call
P. Now when we say P has coordinates x and y, what we are implicitly
saying is a *vector* equation

P = x*u + y*v

with

x = r*cos(A)
y = r*sin(A)

And when we then refer to alternate coordinates, we are using other,
new, unit vectors U and V, where U is aligned with P, and

P = r*U + 0*V

The truth is, coordinates have always depended on this kind of meaning
implicitly. Now in *vector* terms we know that

U =  cos(A)*u + sin(A)*v
V = -sin(A)*u + cos(A)*v
=  cos(A+90deg)*u + sin(A+90deg)*v

Our rotated point in *vector* terms should be

P' = cos(A')*r*U + sin(A')*r*V

But substituting for U and V, we get

P' = cos(A')*r*(cos(A)*u + sin(A)*v)
+  sin(A')*r*(-sin(A)*u + cos(A)*v)
= cos(A')*r*cos(A)*u + cos(A')*r*sin(A)*v
+  -sin(A')*r*sin(A)*u + sin(A')*r*cos(A)*v
= (cos(A')*x - sin(A')*y)*u
+ (sin(A')*x + cos(A')*y)*v

And since the values multiplying u and v are the coordinates of our
new P', we have just discovered (again) that

x' = cos(A')*x - sin(A')*y
y' = sin(A')*x + cos(A')*y

Not only did we not use "sum of angles" substitution, we acquired a
new and vastly improved way to tackle all kinds of transforms, not
just rotations.

### Help with understanding rotations

Hi Just d' FAQ's,

First of all, thank you very much for taking the time to respond to my
post, you obviously understand this well as you describe it very
clearly, cheers.

I think I have an appreciation for what you are saying, but I would be
grateful if you could check my understanding of what you have just
said.

--to achieve rotation by angle A'. But now I want to introduce you to
a
--more powerful way to say this.

thanks v.much for this

--We will speak, not of mere coordinates, but of geometric objects
that
--are independent of coordinates. We will speak of vectors. So our
given
--coordinate system consists of two unit *vectors*, which I will call
u
--and v. And our given object to rotate is a *vector*, which I will
call
--P. Now when we say P has coordinates x and y, what we are implicitly
--saying is a *vector* equation

--P = x*u + y*v

I think I understand this, u and v are our axis vectors (I like this
because I was wondering what an 'axis' was - this is much simpler) and
in our cartesian x/y system these are equal to 1.

I can now perform rotation then by either rotating the co-ordinate
system (u and v axis, P.x and P.y will remain the same as they are
described relative to u and v) leaving P unchanged OR by leaving the
co-ordinate system as it is and rotating P within the co-ordinate
system.

By doing this I think we are saying that a position/definition of a
geometrical object only makes sense when described relative to a
co-ordinate system which itself can be defined relative to another
co-ordinate system etc. My definition of vector P doesn't change, but
the co-ordinate system in which it is housed does.

So I now have a way of transfoming between different 'spaces' using
this technique, to do this I think I have to define a function that
will transform u to u' and v to v'.

As you probably know there is a similar technique in computer science
called 'decoupling' which allows you to reduce dependencies in parts
of a system in such a way that should one part of the system
(co-ordinate space) change, the other part of the system (the rules)
still apply.

I'm still chewing over the technical details of your post but think I
appreciate what you said conceptually.

Thanks for this,

Ben.

### Help with understanding rotations

Quote:>As you probably know there is a similar technique in computer science
>called 'decoupling' which allows you to reduce dependencies in parts
>of a system in such a way that should one part of the system
>(co-ordinate space) change, the other part of the system (the rules)
>still apply.

This would be a good time to explore the following work.

<http://www.cgl.uwaterloo.ca/Software/Geometry/>

Hello, I'm having difficulty implenting axis/angle rotation. As a point of
reference, I'm using the standard conversion from axis/angle to matrix
(Graphics Gems I, p 466 for example)

The problem is this: I want to orient the Z axis of my model along an axis,
with some amount of rotation along the Z axis. When I supply the routine
with my normalized axis pointing somewhere, and an angle who's value is ZERO
(because I don't want angle Z axis roll), I don't get any rotation.

sin(angle) = 0, which then destroys my axis information

Providing other angular values do not yield the expected result either. I
must obviously be providing the wrong angle information or misunderstanding
it's purpose. Should I first rotate my model along it's local Z axis, then
try to align it to a vector? If that's the case, what is the correct value
to provide for the angle component?

Thank you,
John Balestrieri

8. models