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.

# Thread: Another Method,

1. ## 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?

2. ## Re: Another Method,

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

3. ## Re: Another Method,

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.

A little more info

4. ## 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. ## Re: Another Method,

Uber bump?

I solved this issue so long ago.