Calculating a Rotated Vector in 2D with FPS Camera

In summary, the conversation revolves around implementing a FPS-camera and calculating a new vector from another one that is rotated. The correct equations for rotation in 2D are given, as well as a suggestion to use a 3D rotation matrix. There is a discussion about a possible error in the equations, which is eventually resolved.
  • #1
danne89
180
0
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
 
Mathematics news on Phys.org
  • #2
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
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:
  • #4
Consider two vectors which length is the same (rotation doesn't change the lenght, I think) and build two similar trinagles by add two lines from their 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
Sin(pi- a)? But a isn't an angle, it is a length. Where did you get this?
 
  • #6
I don't understand your description. A diagram would be helpful.
 
  • #7
HallsofIvy said:
Sin(pi- a)? But a isn't an angle, it is a length. Where did you get this?
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. :blushing: Oops.
EDIT2: Can you even assume they're equal? I think I've made a complete fool of myself.
 

Attachments

  • diagram.bmp
    68.8 KB · Views: 574
Last edited:

Related to Calculating a Rotated Vector in 2D with FPS Camera

1. How do I calculate a rotated vector in 2D with an FPS camera?

To calculate a rotated vector in 2D with an FPS camera, you will need to use trigonometric functions such as sine and cosine. First, determine the angle of rotation of your camera. Then, use the sine and cosine of that angle to calculate the new x and y coordinates of the vector. Finally, combine the new coordinates to create the rotated vector.

2. What is the purpose of calculating a rotated vector in 2D with an FPS camera?

The purpose of calculating a rotated vector in 2D with an FPS camera is to accurately represent the direction and movement of objects in a 2D game or simulation. This is important for creating a realistic and immersive experience for the player or user.

3. Can I use a different method to calculate a rotated vector in 2D with an FPS camera?

Yes, there are multiple ways to calculate a rotated vector in 2D with an FPS camera. Some other methods may involve using matrix multiplication or rotation matrices. However, using trigonometric functions is a common and simple approach.

4. What factors should I consider when calculating a rotated vector in 2D with an FPS camera?

When calculating a rotated vector in 2D with an FPS camera, you should consider the angle of rotation of your camera, the starting coordinates of the vector, and the size and orientation of your game or simulation world. It is also important to ensure that your calculations are done consistently and accurately.

5. Are there any challenges or limitations when calculating a rotated vector in 2D with an FPS camera?

One challenge when calculating a rotated vector in 2D with an FPS camera is ensuring that the rotation is smooth and continuous. This may require using more complex mathematical functions or techniques. Additionally, if the angle of rotation is too large, it may cause distortion or inaccuracies in the calculation. It is important to test and adjust your calculations to ensure they are accurate and visually appealing.

Similar threads

  • General Math
Replies
1
Views
726
Replies
17
Views
2K
Replies
2
Views
1K
  • General Math
Replies
11
Views
1K
  • General Math
Replies
4
Views
1K
Replies
14
Views
1K
  • Precalculus Mathematics Homework Help
Replies
1
Views
1K
Replies
3
Views
2K
Back
Top