Thatdude1
Thatdude1

Reputation: 903

Shape Intersection

I have shapes that use the Area class to represent its structure. I want to check whether a segement determined by two Points (start point and end point) intersects with Area. Such that segments start and end point are outside the Area (not considering partial line through the area).

The Area class has methods that check is Rectangle2D intersects the area but not a line http://docs.oracle.com/javase/7/docs/api/java/awt/geom/Area.html

Any suggestions or should I try a diffrent approach?

Upvotes: 0

Views: 407

Answers (2)

StanislavL
StanislavL

Reputation: 57381

You can use BasicStroke. Pass the line and get stroked Shape (e.g. thickness=3) then just check the original Area and the stroked shape intersection.

Upvotes: 1

Guillaume Polet
Guillaume Polet

Reputation: 47608

Area has a simple method to do that:

java.awt.geom.Area.intersect(Area)

therefore, you can simply pass your segment to that method and verify if the result equals to the provided parameter.

Upvotes: 3

Related Questions