# Direction,

• May 21st, 2010, 05:05 PM
Time
[SOLVED] Direction,
Ok, here's the idea.

Point A is a random location,

It wants to travel to point b an adjacent point, I need a method to return the direction of the prime point A, in perspective to point b,

i.e if a point is at, 0,0 and A point (adjacent) Is at point 1,1, The method return north-east (String),

For a closer look here: (Sorry for poor artistic abilitys,)

http://i49.tinypic.com/20awkfa.jpg

The main Point A = at 0,0 (Lavander)

The adjacent point b is at 1,1 (Lightblue),

The method should return that the relationship shared between the points is Northwest,

Keep these in mind:
Quote:

-Point A is the main point so relationships stem from there,
-The directions are North, Northeast, Northwest, South, Southeast, Southwest, East, West,
Thanks for reading, I hope someone come's up with a method =P

-Time, o->
• May 21st, 2010, 05:16 PM
helloworld922
Re: Direction,
pseudo-code:

1. create a vector from point A to B (just subtract their coordinates)
2. Get the angle from the positive X axis (or any axis you want, this is easiest because there's a built in function to do this)
3. Use if/else statements to see which quadrant it's in, and return the appropriate response
in degrees (assuming all angles are measured counter-clockwise from the positive X-axis):
angle == 0: east
0 > angle < 90: north-east
angle == 90: north
90 > angle < 180: north-west
angle == 180: west
180 > angle < 270: south-west
angle == 270: south
270 > angle < 360: south-east
• May 21st, 2010, 05:21 PM
Time
Re: Direction,
Quote:

Originally Posted by helloworld922
pseudo-code:

1. create a vector from point A to B (just subtract their coordinates)
2. Get the angle from the positive X axis (or any axis you want, this is easiest because there's a built in function to do this)
3. Use if/else statements to see which quadrant it's in, and return the appropriate response
in degrees (assuming all angles are measured counter-clockwise from the positive X-axis):
angle == 0: east
0 > angle < 90: north-east
angle == 90: north
90 > angle < 180: north-west
angle == 180: west
180 > angle < 270: south-west
angle == 270: south
270 > angle < 360: south-east

Thank's method created and it works like a charm.