I had previously asked this for 3D but now I changed my strategy and would like to do the intersection in 2D.
The Rectangle is axis aligned and will always be in a fixed position, and has a constant shape and size, basically I want to clip the red areas of the triangles that extend outside the bounds of the rectangle. The triangles could be in any position, shape or size, I my code I have a loop where I check the triangles one by one, however I am still clueless about the math.
I have identified 5 cases of triangle rectangle intersection as shown here.
How do I find the intersection points of the triangle and the rectangle?
Answer
The Sutherland-Hodgman polygon clipping algorithm should work just fine for triangle vs. rectangle clipping. You'll find some more information about clipping algorithms here. Or just search for "Sutherland Hodgman clipping".
No comments:
Post a Comment