Bob Doe
Bob Doe

Reputation: 41

How can I get the intersection of a line and a polygon?

So I have a list of points here.

private List<Point> points; 

and the points class just has x,y,z values but only x,y are used in this case. So I store all the polygon points in there

and then I have this method here.

public Point getIntersection(Crossable aLine) {
}

And aLine is just two points so it has 4 values total for x1,x2,y1,y2 etc.

I want to get the intersection of the Line and the polygon, I have no understanding of how to get the intersection since there are a lot of variables involved and special cases. Any ideas?

Upvotes: 1

Views: 69

Answers (1)

Mr.D
Mr.D

Reputation: 67

Consider every two adjacent points of the polygon as a line and check to see if it intersects with your line. You need a loop to go through them all.

Upvotes: 1

Related Questions