# Rotating a vector

1. Jul 20, 2009

### wraithseeker

Lets say I have a velocity vector thats going to the east and I want it's direction to change to somewhere else like west, how would I be able to do that?

What would be the maths required for this? The velocity vector already have a length and a direction.

2. Jul 20, 2009

### maverick_starstrider

You'd use a rotation matrix which is an example of a change of basis. The type of math is linear algebra

3. Jul 20, 2009

### maverick_starstrider

assuming you're working 2D (no up or down) the matrix to rotate a vector by theta is $\begin{bmatrix} \cos \theta & \sin \theta \\[3pt] -\sin \theta & \cos \theta \\ \end{bmatrix}$

4. Jul 20, 2009

### wraithseeker

I searched wikipedia but it was too confusing so i asked for help here.

5. Jul 20, 2009

### maverick_starstrider

3D's a little more complicated since rotations do not commute. For example, if you think of an airplane it can do 3 things it can pitch, roll and yaw http://www.ultimatepointer.com/images/YawPitchRoll.jpg [Broken] Now the thing is that order matters. If you were to roll 90 degrees and then yaw 90 degrees your plane would not be in the same orientation then if you were to yaw 90 degrees then pitch 90 degrees. This means there's no one matrix to rotate any vector to any vector you instead have to think about the orientation and apply multiple in sequence, in the correct sequence (like pitch,roll,yaw). This should help http://en.wikipedia.org/wiki/Rotational_matrix if you haven't found it yet.

Last edited by a moderator: May 4, 2017
6. Jul 20, 2009

### wraithseeker

For 2D I still don't really get you, do I multiply it by cos angle and sin angle or the one below?

Or do I subtract it.

7. Jul 20, 2009

### maverick_starstrider

Have you never covered matrix multiplication?

$\begin{bmatrix} \cos \theta & \sin \theta \\[3pt] -\sin \theta & \cos \theta \\ \end{bmatrix}\begin{bmatrix} x \\[3pt] y\\ \end{bmatrix}=\begin{bmatrix} \cos\theta x + \sin \theta y \\[3pt] -\sin \theta x + \cos \theta y\\ \end{bmatrix}$

so you get the new x is $\cos\theta x + \sin \theta y$ and the new y is $-\sin \theta x + \cos \theta y$

8. Jul 20, 2009

### maverick_starstrider

In general for 2x2 matrices:

$\begin{bmatrix} a& b\\[3pt] c & d \\ \end{bmatrix}\begin{bmatrix} x \\[3pt] y\\ \end{bmatrix}=\begin{bmatrix} a x + b y \\[3pt] c x + d y\\ \end{bmatrix}$

9. Jul 20, 2009

### HallsofIvy

For rotations in 3 dimensions, you need to state an axis of rotation as well as an angle. That's why they are so much complicated.

10. Jul 20, 2009

### wraithseeker

Is it taken in radians or degrees currently?

Here's how I tried to apply it

vx = Cos(angle)*vx+ Sin(angle)*vy
vy = -Sin(angle)*vx+Cos(angle)*vy

vx = velocity X
vy = velocity Y
angle = new angle

11. Jul 20, 2009

### Born2bwire

Doesn't matter, the cosine of 90 degrees is the same as the cosine of 0.5*\pi. One note, the angle \theta is not the "new" angle, it is the angle of rotation.

12. Jul 20, 2009

### wraithseeker

Ok a slighty offtopic question, is rotating a vector the same as changing the direction of a vector? How would you change the direction of a vector?

vx = vx *Cos(angle)
vy = vy *Sin(angle)

or am I wrong?

13. Jul 20, 2009

### Born2bwire

This formula does not preserve the vector's magnitude.

14. Jul 20, 2009

### wraithseeker

Where can I find it? I googled to no avail too.

15. Jul 20, 2009

### Born2bwire

maverick already gave you the rotation matrix for a 2D Cartesian coordinate system. If you want to rotate a vector, you use the appropriate rotation matrix. If you want to make a vector point in a desired absolute direction then you simply make a unit vector that points in the desired direction and scale it to the desired length.

16. Jul 20, 2009

### wraithseeker

I tried that but it didn't work that's why I asked about the direction.

vx = Cos(angle)*vx+ Sin(angle)*vy
vy = -Sin(angle)*vx+Cos(angle)*vy

I did something like this.

Imagine actual angle is the front of the person but after setting the values, I set it to be 90 degrees that will be converted to radians but it bugs as the example shown above.

The angle of the ball thrown is always different from any position.

17. Jul 20, 2009

### Born2bwire

What example? If it's 90 degrees then the rotation is straightforward:

v_x = v_y;
v_y = -v_x;

If our vector is (0,1), we can see that we easily get the correct vector of (1,0). Note that maverick's rotation matrix is a clockwise rotation with respect to the traditional x-y plane orientation.

18. Jul 20, 2009

### wraithseeker

I solved it, thanks guys.

19. Oct 17, 2009

### thimmsoft

Hi am new to this forum, i am working on spherical modal analysis. I need some help in rotation . One of the step in my analysis is to align the axis of reference of the field waves of the radiator to the axis of the dielectric lens. How should i proceed and do i have to use rotation matrix? Is rotation matrix different from wigner rotation matrix? Which matrix should i employ ?

If my question is absurd pls ask me so that i can put my question clearly...........