Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate a vector from an angle with another vector in 2D?

I know I should know this, but I just can't figure it out/find the solution. I can do it by hand, but I can't put it in an algorithm... (working in c++, but pseudocode should be fine).

I have a vector, and I want to find another vector based on the angle with it.

Angle with two vectors

v is known, angle alpha is known and the magnitude of w is known. How can I find w?

Thanks!

like image 515
Tessa Avatar asked Aug 02 '12 08:08

Tessa


People also ask

How do you find a vector given an angle?

Given a position vector →v=⟨a,b⟩,the magnitude is found by |v|=√a2+b2. The direction is equal to the angle formed with the x-axis, or with the y-axis, depending on the application. For a position vector, the direction is found by tanθ=(ba)⇒θ=tan−1(ba), as illustrated in Figure 8.8.


1 Answers

To rotate a vector v = (x, y) by an angle alpha clockwise about the origin, you can multiply by the matrix:

[  cos alpha    sin alpha ]
[ -sin alpha    cos alpha ]

Thus the rotated vector with the same magnitude will be

(x cos alpha + y sin alpha, -x sin alpha + y cos alpha).

To change the magnitude from |v| to |w|, multiply both co-ordinates by |w|/|v|.

like image 175
Simon Nickerson Avatar answered Oct 15 '22 07:10

Simon Nickerson