Convert angle (radians) to a heading vector?

$\begingroup$

I have been looking everywhere trying to find out how to convert an angle in radians (expressed as -Pi to Pi) to a heading vector.

The only [x,y] answer I have found is, [cos(angle), sin(angle)] , however, this doesn't work! Or am I missing something?

I just want a vector pointing at a direction of a specified angle, and for it to have a magnitude of 1, such is called a "heading vector" I believe. At least it is in the various game code I look at.

CLARIFICATION:

A heading vector is a vector with a magnitude of 1 with the start at 0, and the end (the arrowhead) at some value within a unit circle. A heading vector is a way of showing direction as a vector. I want to take an angle and express it as a vector, however, people seem to just be telling me how to do unit conversions.

I appreciate you trying to be helpful, however, hopefully these clarifications will guide others to giving more fitting responses.

Thanks.

$\endgroup$ 10

3 Answers

$\begingroup$

Your information is correct.

If you have an angle (A), in radians, in the range -Pi to Pi, then convert it to a vector (V) with:

V.x = cos(A)
V.y = sin(A)

The inverse is A = atan2(V.y, V.x)

If it doesn't work in your games code you should be looking for a typing error, or other silly little bug. Its not the maths.

$\endgroup$ 3 $\begingroup$

To convert radians to degrees, you multiply by $\frac {180}{\pi}$. The standard positions for angles and headings are different, as The Chaz has commented. To go from a regular angle of $\theta$ to a heading, the heading is $\frac {\pi}2 - \theta$ in radians or $90^\circ -\theta$ in degrees.

$\endgroup$ $\begingroup$

If you have an angle between north and vertical axis (which equals to negative the bearing) where North ($0°$) is at $(0,1)$, then your vector would be

$u = sin(\theta)$

$v = cos(\theta)$

for any degree $\theta$.

To think of it visually, just consider what $sin(\theta)$ and $cos(\theta)$ look like as $\theta$ changes, and compare them to how you expect $u$ and $v$ to change.

enter image description here

$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like