Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

Strange problem intersecting java.awt.Polygon

Thread view: 
418928@cepsz.unizar.es - 12 Nov 2007 18:54 GMT
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
Lew - 12 Nov 2007 19:04 GMT
> Hi everybody,
>
[quoted text clipped - 17 lines]
> 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.

Signature

Lew

418928@cepsz.unizar.es - 12 Nov 2007 23:26 GMT
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

> 418...@cepsz.unizar.es wrote:
> > Hi everybody,
[quoted text clipped - 26 lines]
> --
> Lew
Andrew Thompson - 12 Nov 2007 23:56 GMT
...
>Thanks for any suggestion!

1) Refrain from top-posting.
2) Post an SSCCE*.

* <http://www.physci.org/codes/sscce.html>

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Lew - 13 Nov 2007 00:11 GMT
>>> java.awt.Polygon pol = new java.awt.Polygon();
>>> pol.addPoint(1, 0);
>>> pol.addPoint(1, 1);
>>> pol.addPoint(0, 1);

> 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)

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.