By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,538 Members | 1,130 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,538 IT Pros & Developers. It's quick & easy.

a simple 2d question

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Well, the last example were quite bad...
How about the following one:

Line2D.Double l = new Line2D.Double(120, 120, 240, 240);
if(l.intersects(140, 190, 150, 200)) System.out.println("1");

Why does this result in the output "1"? The line l definitely doesn't
intersects the square.
Jul 17 '05 #2

P: n/a
Dominik Kaspar wrote:
Well, the last example were quite bad...
How about the following one:

Line2D.Double l = new Line2D.Double(120, 120, 240, 240);
if(l.intersects(140, 190, 150, 200)) System.out.println("1");

Why does this result in the output "1"? The line l definitely doesn't
intersects the square.


Dominik,

Are you reading the javadoc correctly? Note that Line2D.intersect()
expects the x-coord, y-coord, the width and the height of the rectangle
(contrast with the Line2D.Double constructor). So the point (240,240)
is inside your rectangle as:

140 <= 240 <= 290 = 140+150 and
190 <= 240 <= 390 = 190+200

Ray

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.