# How can I get coordinates for a position given a specified heading in degrees?

• December 21st 2009, 04:21 PM
Aphex
How can I get coordinates for a position given a specified heading in degrees?
Hi Maths forum :)

The problem I have is actually for a program I am writing, I just cant figure it out though.

Let's say I have a fixed 2D cooridnate system using Y and X coords, I also have a character that can be facing in any direction. His direction is given as a heading in degrees. For example, 0° is north (Y direction), 180° is south (-Y direction) X is east...etc...

Let's say I wish to find the coordinates of a point that is directly in front of the person, no matter which way he is facing. For instance, I might want the coords for 2 units in front of the character. How would I do this? To make it more clear, if the character is facing south (180°), the position I am looking for will be (-2, 0)

Can anyonep provide an equation for this?

thanks for any answer :D Much appreciated
• December 21st 2009, 04:44 PM
skeeter
Quote:

Originally Posted by Aphex
Hi Maths forum :)

The problem I have is actually for a program I am writing, I just cant figure it out though.

Let's say I have a fixed 2D cooridnate system using Y and X coords, I also have a character that can be facing in any direction. His direction is given as a heading in degrees. For example, 0° is north (Y direction), 180° is south (-Y direction) X is east...etc...

Let's say I wish to find the coordinates of a point that is directly in front of the person, no matter which way he is facing. For instance, I might want the coords for 2 units in front of the character. How would I do this? To make it more clear, if the character is facing south (180°), the position I am looking for will be (-2, 0)

Can anyonep provide an equation for this?

thanks for any answer :D Much appreciated

using a standard trig angle reference ... east = 0 degrees, north = 90 degrees, west = 180 degrees, south = 270 degrees

$x = r\cos{\theta}$

$y = r\sin{\theta}$

where $\theta$ is the angle referenced from east (0) , and $r$ is the distance from the origin.
• December 21st 2009, 05:29 PM
Aphex
Thanks for that.

Although, I haven't used sin and cos for so long, could you give me an brief worked example. Is something like this correct? The coordinates seem to come out wrong
Quote:

heading = 200 degrees from east
distance from origin = 2

x = 2 * cos(200)
y = 2 * sin(200)

x = -1.87
y = -0.68
• December 21st 2009, 05:34 PM
skeeter
those coordinates are correct ... 200 degrees is in quad III , x and y are both negative.
• December 21st 2009, 05:59 PM
Aphex
Your right, they are pretty much correct, although, not quite how they should be. Here is another example though.

Quote:

heading = 300 degrees from east
distance from origin = 2

x = 2 * cos(300)
y = 2 * sin(300)

x = 1
y = -1.73
Surely thats not right.
• December 21st 2009, 06:23 PM
skeeter
note that angles are measured counter-clockwise from 0 degrees (east)

300 degrees is in quadrant IV ... x is positive, y is negative ... and the values you calculated are correct.

need more confirmation? go to the link ...

Convert Polar to Rectangular Coordinates - Calculator
• December 21st 2009, 06:54 PM
Aphex
Thanks for all your replies. This does make sense when thinking of it travelling counter-clockwise and starting from east.

Cheers