Strange problem intersecting java.awt.Polygon

4

418928

Hi everybody,

I have a strange problem. I am defining a polygon and I try to see if
it intersects other rectangular shape. Specifically:

java.awt.Polygon pol = new java.awt.Polygon();
pol.addPoint(1, 0);
pol.addPoint(1, 1);
pol.addPoint(0, 1);

if (pol.intersects(0, 0.9, 0, 0.1))
{
System.out.println("Intersects here!");
}
else
{
System.out.println("Do not intersect here!");
}

And it says: "Do not intersect here!". I'm confused. There should be
an intersection...

I also tried with:

if (pol.intersects(-0.01, 0.09, 0.01, 0.01))
{
System.out.println("Intersects here1!");
}
else
{
System.out.println("Do not intersect here1!");
}

And it says again: "Do not intersect here!".

I'm really confused! I hope you can help me!!

About the context of my problem: I have a polygon P and a rectangle R.
I need to check if R intersects P. If just some points in the boundary
of P match with points of R, that's also an intersection for my
purposes (that's why I enlarge R a little bit -0.01 pixels in each
direction, for example- before calling "intersects"). However, it
doesn't work as expected.

I hope you can give me some idea about why this isn't working and how
to solve it!!

Thanks a lot in advance,

Sergio
 
L

Lew

Hi everybody,

I have a strange problem. I am defining a polygon and I try to see if
it intersects other rectangular shape. Specifically:

java.awt.Polygon pol = new java.awt.Polygon();
pol.addPoint(1, 0);
pol.addPoint(1, 1);
pol.addPoint(0, 1);

if (pol.intersects(0, 0.9, 0, 0.1))
{
System.out.println("Intersects here!");
}
else
{
System.out.println("Do not intersect here!");
}

And it says: "Do not intersect here!". I'm confused. There should be
an intersection...

the line from (0.0, 0.9) of width 0.0 and height 0.1 just touches a vertex of
the triangle held in the Polygon, the vertex at (0.0, 1.0). This vertex is
not in the interior of the Polygon { (1.0, 0.0), (1.0, 1.0), (0.0, 1.0) }, but
on the edge, therefore intersects() must return false.
 
4

418928

Thanks Lew,

I have also tried with "pol.intersects(-0.01, 0.09, 0.01, 0.01)"
without success. I also tried using Rectangle2.Double as argument of
"intersects" and other widths and heights. I think there is some
problem... I'm using Java 1.5. (I understand I'm computing the
intersection between a polygon and a rectangle).

Thanks for any suggestion! I'm stuck!

Sergio
 
L

Lew

I have also tried with "pol.intersects(-0.01, 0.09, 0.01, 0.01)"
without success.

A rectangle of height and width 0.01 that starts at (-0.01, 0.09) is not going
to intersect the stated polygon either.

0.......(1,0)
/ |
/ |
/ |
/ |
(0,1)...(1,1)
 

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

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top