Here you can find the source of angleToPoint(Rectangle r, double angle)
public static Point angleToPoint(Rectangle r, double angle)
//package com.java2s; //License from project: Open Source License import java.awt.*; import java.awt.geom.Rectangle2D; public class Main { public static Point angleToPoint(Rectangle r, double angle) { double si = Math.sin(angle); double co = Math.cos(angle); double e = 1.0E-4D; int x = 0; int y = 0; if (Math.abs(si) > e) { x = (int) ((1.0D + co / Math.abs(si)) / 2.0D * (double) r.width); x = range(0, r.width, x);// w w w .j a v a 2 s.c o m } else if (co >= 0.0D) { x = r.width; } if (Math.abs(co) > e) { y = (int) ((1.0D + si / Math.abs(co)) / 2.0D * (double) r.height); y = range(0, r.height, y); } else if (si >= 0.0D) { y = r.height; } return new Point(r.x + x, r.y + y); } public static java.awt.geom.Point2D.Double angleToPoint(Rectangle2D.Double r, double angle) { double si = Math.sin(angle); double co = Math.cos(angle); double e = 1.0E-4D; double x = 0.0D; double y = 0.0D; if (Math.abs(si) > e) { x = (1.0D + co / Math.abs(si)) / 2.0D * r.width; x = range(0.0D, r.width, x); } else if (co >= 0.0D) { x = r.width; } if (Math.abs(co) > e) { y = (1.0D + si / Math.abs(co)) / 2.0D * r.height; y = range(0.0D, r.height, y); } else if (si >= 0.0D) { y = r.height; } return new java.awt.geom.Point2D.Double(r.x + x, r.y + y); } public static int range(int min, int max, int value) { if (value < min) { value = min; } if (value > max) { value = max; } return value; } public static double range(double min, double max, double value) { if (value < min) { value = min; } if (value > max) { value = max; } return value; } }