# Vector rotation

1. Apr 2, 2005

### danne89

Hi! I'm trying to implement a FPS-camera. I need to calculate a new vector from another one, rotated a.

This is of cource in 2D. Is this correct:
x' = x * ||v|| sin a / y
y' = - y ||v|| cos a / x

2. Apr 2, 2005

### gerben

if you want to rotate a vector (x, y) of an angle a to get a vector (x', y') you just need this:

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

3. Apr 2, 2005

### danne89

Ahh! Exactly what I was looking for.

EDIT: Hello there! I found that my copy of Core Algorithms in Game Programming has a matrix for my 3D rotation.

Last edited: Apr 2, 2005
4. Apr 2, 2005

### danne89

Consider two vectors which lenght is the same (rotation doesn't change the lenght, I think) and build two similar trinagles by add two lines from thier heads to the x-axes. Name them v=(x, y) and u=(a,b). Then obiously x/a =y/b. x=ay/b=a*||v|| sin(Pi - a)/b = x=a * ||v|| sin a /b In a similar way one can derive the other equation. Where is my error?

5. Apr 2, 2005

### HallsofIvy

Sin(pi- a)? But a isn't an angle, it is a length. Where did you get this?

6. Apr 2, 2005

7. Apr 2, 2005

### danne89

Woops! It should be the angle between the vectors. Call it alpha istead. My own diagram tricked me.

EDIT: When I think about it. Shouldn't it be (Pi-alpha)/2. Oops.
EDIT2: Can you even assume they're equal? I think I've made a complete fool of myself.

#### Attached Files:

• ###### diagram.bmp
File size:
68.8 KB
Views:
138
Last edited: Apr 2, 2005