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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Direction,

  1. #1
    Member
    Join Date
    May 2010
    Posts
    39
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default [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,
    Last edited by Time; May 21st, 2010 at 05:21 PM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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. #3
    Member
    Join Date
    May 2010
    Posts
    39
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: Direction,

    Quote Originally Posted by helloworld922 View Post
    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.