**1**

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

Started by Jul 26 2012 07:09 AM

,
4 replies to this topic

###
#1
Members - Reputation: **936**

Posted 26 July 2012 - 07:09 AM

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

bounding box parallel to the world space axis.

bounding box parallel to the local X axis of one of the 2 rectangles

Ps: i have the transformation matrices of both rectangles

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

bounding box parallel to the world space axis.

bounding box parallel to the local X axis of one of the 2 rectangles

Ps: i have the transformation matrices of both rectangles

###
#2
Members - Reputation: **786**

Posted 26 July 2012 - 08:41 AM

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?

or something with Minkowski Sum...

but why you dont want to use axis aligned bounding boxes?

**Edited by serumas, 26 July 2012 - 08:43 AM.**

###
#3
Members - Reputation: **936**

Posted 26 July 2012 - 11:58 AM

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?

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?

###
#4
Crossbones+ - Reputation: **3899**

Posted 26 July 2012 - 02:04 PM

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.

###
#5
Members - Reputation: **786**

Posted 26 July 2012 - 03:13 PM

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?

why tou need pixel perfect collision for?

do you try to make xor and or ... functions for polygons?