• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Java] need help detecting line intersection

Status
Not open for further replies.
Level 10
Joined
Sep 29, 2006
Messages
447
So I'm trying to use the even-odd parity rule to determine if a point lies inside a polygon. You draw a directed line from your point, and if there are an even number of line intersections, the point lies outside the polygon, if there is an odd number, the point is inside.

My code snipped looks like this so far:

Code:
public boolean insidePolygon(Point p) {
    :
    :
    :

    int count = 0;
    int numSides = edgeList.size();  //edgeList is an ArrayList<edges> object
    for (int i = 0; i < numSides; i++) {
        edge e = edgeList.get(i);
        if (intersect(ray, e))
            count++;
    }
    if (count%2 == 0) 
        return false;
    return true;
}

private boolean intersect(edge e1, edge e2) {
    //I have no idea what to put here!
    return false;
}


My problem is that I don't know how to detect if two line segments intersect. For all intents and purposes an edge object is a line segment. Each edge only contains two Point objects as fields and that's it. edgeList is an ArrayList of edges containing all the edges of my polygon.

So what do I need to put in the intersect() method?
 
Status
Not open for further replies.
Top