Hello
I want to catch mouse clicks on drawn lines and was dumbfound by the
Line2D.intersects method.
My code looks like this:
Line2D.Double l = new Line2D.Double(0, 0, 100, 100);
if(l.intersects(49, 49, 51, 51)) System.out.println("1");
if(l.intersects(35, 35, 37, 37)) System.out.println("2");
The line (0,0)-(100,100) definitely doesn't intersect with the
rectangle (35,35)-(37,37). But why the hell does the above code give
the output "1" and "2"?!
I hope somebody can eliminate my confusion.
Dominik
Dominik Kaspar - 19 Nov 2003 16:20 GMT
Hmm, bad example...
Why does the following give the output "1"?
Line2D.Double l = new Line2D.Double(120, 120, 240, 240);
if(l.intersects(140, 190, 150, 200)) System.out.println("1");
Dominik
> Hello
>
[quoted text clipped - 12 lines]
> I hope somebody can eliminate my confusion.
> Dominik
Sujatha S G - 20 Nov 2003 03:11 GMT
The Output is correct, May be you are thinking that you are drawing a
horizontal line. But you are drawing a line in 45 deg angle. And the
rectangle points you are giving will definitely intersect. may be you can
checn in "mspaint" by drawing this lines and rectangles.
> Hmm, bad example...
> Why does the following give the output "1"?
[quoted text clipped - 19 lines]
> > I hope somebody can eliminate my confusion.
> > Dominik