Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. [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,)

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:
-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,

2. 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

3. Re: Direction,

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.