Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Angle between 2 points

807598May 21 2006 — edited May 21 2006
Hi,

I have two points (I am drawing 2 circles) and have to measure the angle between these 2 points - they are connected with a line.

I know that I have to do something like
Math.toDegrees(Math.atan2(x,y))
but I don't know how to exactly implement it.


I thought about doing something like the following:
boolean angleGreaterThan45(Line2D lineBetweenPoints, Point2D pointCenter) {
  return pointCenter.Math.toDegrees ( Math.atan2 ( lineBetweenPoints.x, lineBetweenPoints.y ) ) );
}
However this doesn't work...

The 2 points are coded like this:
public Point createStartPoint() {
  Random rand = new Random();
  startX = rand.nextInt(maxStartX + 1);
  startY = rand.nextInt(maxStartY + 1);
  return new Point(startX, startY);
}
...and the line between the 2 points like this:
Line2D.Double lineBetweenPoints, = new Line2D.Double(startPoint, endPoint);
Thanks a lot for your help!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 18 2006
Added on May 21 2006
11 comments
229 views