Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rotate vector 90 degrees to the right

Started by smittix Oct 22, 2009 at 11:02 PM 3 replies 20.7k views
Original Post
smittix
smittix
Given one normalized 2D vector, how can I get the vector that is rotated 90 degrees to the right about the z-axis? So given a vector of (0, 1), how would I get the vector (1, 0)? I used to know how to do this... something like: Vector2D right = Vector2D(Cos(dirToTarg.y), -Sin(dirToTarg.x)); That's not right but I think it's close..
kdworld
kdworld
you can use the following rotation matrix.

x is in radian.. ( radian = degree * Pi / 180; )

[ cos x -sin x ]
[rot] = [ ]
[ sin x cos x ]

multiply your vector with this..

v = v * rot; v is a row vector.



fastcall22
fastcall22
Quote:

Vector2D right = Vector2D(Cos(dirToTarg.y), -Sin(dirToTarg.x));


Erm, is dirToTarg a pair of angles?

Vector2D right = Vector2D( dirToTarg.y, -dirToTarg.x );
smittix
smittix
Ah.. yeah I think that's what I was looking for _fastcall, thanks. And dirToTarg is the initial vector (1, 0) that I wanted to rotate.
h4tt3n
h4tt3n
Quote:
Original post by bengaltgrsGiven one normalized 2D vector, how can I get the vector that is rotated 90 degrees to the right about the z-axis? So given a vector of (0, 1), how would I get the vector (1, 0)?

I think what you want to find is the normal vector, not to be confused with the normalized vector. A vector normal can point either 90 degrees to the right or left of the original vector. The right-hand normal of vector (x, y) is (y, -x), and the left-hand normal is (-y, x). Plane and simple, no need for trig functions.

Cheers,
Mike

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.