• Advertisement
Sign in to follow this  

Java Problem - line intersecting GeneralPath

This topic is 3865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to create a method that will allow me to determine if a given straight line will intersect a given GeneralPath. Basically, I'm trying to create the body for this method: public boolean intersects(GeneralPath P, double x1, double y1, double x2, double y2) { ... } where the straight line is from points (x1,y1) to (x2.y2). Any help would be much appreciated

Share this post


Link to post
Share on other sites
Advertisement
EDIT:

I should read more carefully, you are talking about line segments. In that case, I believe GeneralPath implements an intersects() method.

I don't know if it is mathematically feasible to check if a line intersects a complex shape such as a GeneralPath. That is why games generally resort to bounding boxes to make collision detection easier. The solution depends on what you are trying to accomplish and how accurate you need the method to be. If converting your GeneralPath to a rectangle sounds acceptable, check the Rectangle2D class and specifically the intersectsLine() method.

http://java.sun.com/javase/6/docs/api/java/awt/geom/Rectangle2D.html

Share this post


Link to post
Share on other sites
Get PathIterator from GeneralPath.

Test every segment of the path iterator to your line (Line2D class).

Line2D has intersects() method which accepts your format.

I presume that there is no general solution, since intersections can be complex, and getting segment-wise intersections is only one possible case. It gets much more complicated if your path is made up of non-linear segments.

Although, in typical over-engineered Java style, there is no direct implementation of this overly common case, just everything else.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement