Line2D.intersects acting strangely

R

Rick

Hi,

I'm trying to detect collision with an object in 2D space traveling
towards a line (draw using Line2D). the object has vertices x1, y1,
width, height. when I try doing:

Line2D line = new Line2D.Double(l_x1, l_y1, l_x2, l_y2);

if (line.intersects(x1, y1, x1+width, y1+height)) {
System.out.println("Collision!");
}

This isn't working properly. "Collision!" get's printed way too early
even when the object is quite away from the line. The line is something
like:
\
\
\
\
O \
\


Where "O" is the object. Can anyone explain what's happening? Thanks

Rick
 
R

Roedy Green

This isn't working properly. "Collision!" get's printed way too early

I'm just guessing without reading the docs. But is your region
actually a giant rectangle rather than a long skinny line?
 
A

Andrew Hobbs

Rick said:
Hi,

I'm trying to detect collision with an object in 2D space traveling
towards a line (draw using Line2D). the object has vertices x1, y1,
width, height. when I try doing:

Line2D line = new Line2D.Double(l_x1, l_y1, l_x2, l_y2);

if (line.intersects(x1, y1, x1+width, y1+height)) {
System.out.println("Collision!");
}

try

if (line.intersects(x1, y1, width, height)) {

ie look at the docs.

Cheers

Andrew


i
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top