Check if Rectangle is between two points

144 views Asked by At

If I have point A, point B and point C. In Java, how would I check if any of the rectangle is in-between the two points?

1

There are 1 answers

0
River On BEST ANSWER

Try the intersectsLine(Line2D l) method of java.awt.geom.Rectangle2D:

Rectangle2D.Double rect = new Rectangle2D.Double(double x, double y, double w, double h);
System.out.println(rect.intersectsLine(new Line2D.Double(double xA, double yA, double xB, double yB)));

where xA,yA, xB,yB are the x and y coordinates, respectively, of points A and B which you wish to check if the rectangle is between.