# Another Method,

• May 15th, 2010, 12:33 PM
Time
Another Method,
Well yea. Here's basically whats up,

Here's the enum:
Code :

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

http://i43.tinypic.com/2irb0c6.jpg

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

``` 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?
• May 15th, 2010, 02:09 PM
helloworld922
Re: Another Method,
Just get the angle between and do some if-else loops to see which quadrant it's in.
• June 28th, 2010, 04:29 PM
Davidovic
Re: Another Method,
Quote:

Originally Posted by helloworld922
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.
:)