Moving ahead from previous question.I have two rectangle and they look like this:
struct Rect
{
NSPoint topLeft;
NSPoint topRight;
NSPoint bottomLeft;
NSPoint bottomRight;
}
I use something similar code to check whether rectangles intersects(or collision) . In case If 2 rectangles intersects I want to calculate the area of intersection in the first rectangle or the points where the second rectangle intersects with first rectangle (i.e. intersection coordinates).
How do I calculate the intersecting points or the area of intersection.
You can determine the points of intersection by doing this:
to find the intersection point of two lines:
http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
You can find the area of intersection by finding the points of intersection, and splitting the lines based off that to create new sides/delete sides. You could get up to 8 points in the resulting polygon, or as few as 3 (not counting degenerate cases).
No, I didn’t say this is the most efficient method, but it will work 🙂