File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes awt.Shape intersect between different shapes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "awt.Shape intersect between different shapes" Watch "awt.Shape intersect between different shapes" New topic
Author

awt.Shape intersect between different shapes

Tim Sangster
Greenhorn

Joined: Mar 27, 2011
Posts: 12
Hello,

I am trying to make a game for school.
In this game I simulate collision by using the .collision function of the awt.Shape 's I am using.
Now I am adding an object that is not a rectangle and I see that you can not use intersect for a comparison between different shapes.
Is there any build in way to still compare these?

Thanks in advance,

Tim
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
What collision method? (Don't say "function").

Can't think of anything offhand. There are several intersects and contains methods in the GeneralPath class, but I don't know whether they are any improvement for you.

I shall move this discussion to our GUIs forum, where we usually discuss such questions.
Tim Sangster
Greenhorn

Joined: Mar 27, 2011
Posts: 12
Solved
I used the Java 2D Shape Implementations
I want to check if a Rectangle2D intersects with a Ellipse2D.Double or Ellipse2D.Float.
The intersect method I used of java.awt.Shape can only be passed a Rectangle2D Object.
But the problem is solved by calling the intersect method on the Ellipse2D and passing the Rectangle2D instead of the other way around.

If anybody could explain to me why you can not simply compare all shapes (now at least one of them has to be a Rectangle2D) I would be very thankful.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
Well done Don't know why you can only do it that way round. Maybe if I really remember to move you to GUIs somebody there will know. [Even though they are the same people you meet here ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: awt.Shape intersect between different shapes