Saturday, October 7, 2017

Triangle - Rectangle Intersection in 2D



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.Triangle Rectangle Intersections


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

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...