Followers 0

[2D] Bonding Box of collision region of 2 rectangles

4 posts in this topic

Hello,
i'm implementing pixel perfect collision, and in order to make the check faster i want to cull the unused part of the 2 sprites colliding.
I need to find the red area in the pictures (the rectangles can be scaled, rotated, screwed), possibly the one from the last 2 pictures(where the rectangle is parallel to one of the 2 rectangles), but i'm a little confused. I have the vertices in world space, but i can't figure a way to correctly test the right intersections(for each way i think it could be done i can think of a corner case in which it is wrong).

Is there some algorithm to perform this check? I wasn't able to find one, despite the fact it should be a well studied/known subject (at least, i thought 2D collision is a well known and already deeply studied subject..)
Thanks

[attachment=10268:intersection.png]
bounding box parallel to the world space axis.
[attachment=10269:intersection2.png]
[attachment=10270:intersection3.png]
bounding box parallel to the local X axis of one of the 2 rectangles

Ps: i have the transformation matrices of both rectangles
0

Share on other sites
Im not a professional, but i think fastest way of your example, would be "point vs convex polygon" check (perhaps)
or something with Minkowski Sum...
but why you dont want to use axis aligned bounding boxes? Edited by serumas
0

Share on other sites
I have the 4 vertices of the rectangle representing my sprite.
Since i want to enable pixel perfect collision i need to make the fewest check per pixel possible, thus the choice of finding the exact bounding box of the intersecting area.
In addition to the bit mask of the sprite, i have subdivided the rectangle in regions of 32x32 pixels, and store if they are empty, full, or half-filled (so that if a half filled region of a sprite maps to an empty region i can skip 1024 checks and say that they don't collide, and if it maps to a full region i can skip again 1024 checks and say they collide). So, having the bounding box axis aligned to the local axis of the rectangles make the code of checking the square sub-region far easier and more readable.

I'll look into point vs convex polygon, but i'm curious about the Minkowski sum. Can you explain a bit further?
0

Share on other sites
You could do several line-line intersection tests. For every side of each rectangle, intersect with the sides of the other rectangle. You'd also have to check if one of the corners of each rectangle lies inside the other one, a small rectangle could lie inside a bigger one and no line intersections would occur.
0

Share on other sites
minkowski sum is some kind abstract math witch is used in some algoritms like, finding is polygon covex, gjk collision algorithm, polygon expand (if i remember corectly) and so on.
why tou need pixel perfect collision for?
do you try to make xor and or ... functions for polygons?
0

Create an account

Register a new account