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 5 of 5

Thread: Another Method,

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

    Default Another Method,

    Well yea. Here's basically whats up,

    Here's the enum:
    public enum Direction {
     
    	EAST, NORTHEAST, NORTH, NORTHWEST, WEST, SOUTHWEST, SOUTH, SOUTHEAST, UNDEFINED;
     
    }

    I need a method to return a "Direction" ^ based on 2 points i.e:



    All are in perspective to "Me"

    Anypoint in the DarkRed box is north,
    Anypoint in the purple box is north-west
    Anypoint in the Orange box is north-east

    etc etc,

    How the method signature would look like:
    	public static Direction getDirection(Point startPoint, Point endPoint)  {
    		String dirs[] = {"EAST", "NORTHEAST", "NORTH", "NORTHWEST", "WEST", "SOUTHWEST", "SOUTH", "SOUTHEAST"};
    		String direction = dirs[ (int) degree % 8];
    		for(Direction dir : Direction.values()) {
    			if(dir.toString().equalsIgnoreCase(direction)) {
    				return dir;
    			}
    		}
    		return Direction.UNDEFINED;
    	}

    Any ideas?
    Last edited by Time; May 15th, 2010 at 12:36 PM.


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

    Default Re: Another Method,

    Just get the angle between and do some if-else loops to see which quadrant it's in.

  3. #3
    Junior Member
    Join Date
    Jun 2010
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Another Method,

    Quote Originally Posted by helloworld922 View Post
    Just get the angle between and do some if-else loops to see which quadrant it's in.
    Just make a circle and divide it in 8 parts, so that means that for each position you will have 45°. And you will need one more point ( reference ) from which will you calculate the angle, so you can know what quadrant it is.

    A little more info

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Another Method,

    I don't see a definition for the problem.
    What is the relationship between the line (2 points) passed to the method and what you want returned?

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

    Default Re: Another Method,

    Uber bump?

    I solved this issue so long ago.