Plane Collision Detection

Recommended Posts

grisu    100
Hello! Ok, it's simple to check a collision between planes in 2d :) But I too need the distance the planes should move to stop colliding. I need the coordinates of these targetpoints. See this image: http://www.christianchabek.at/stuff/cd.jpg Can anybody help me? I'm no expert in math :) First, I thought of Phytagoras (of course): Just adding the heights of the planes to get a triangle and the desired length of my vector. But this only works with one direction :) This must be a simple task. Thanks in advance!

Share on other sites
phyxle    100
If I underestand correctly you want to find the collision response of two rectangles in 2d. Here is an easy solution.
suppse rectangles have x,y (center) and w, h.

//if there is collision in x direction
if (abs (rect1.x-rect2.x)<(rect1.w+rect2.w)/2.0)
{
colliosnX=(rect1.x+rect2.x)/2.0; //find X of collsion point
rect1.x=colliosnX + sign(rect1.x-colliosnX)* rect1.w/2.0 ;
rect2.x=colliosnX + sign(rect2.x-colliosnX)* rect2.w/2.0 ;
}
I used sign to make sure recttangles stay at the same side that they were.

You should do the same by replacing X with Y and W with H.

Share on other sites
grisu    100
Hi,

What does "sign" do?

I just tried your code, but it doesn't work.
I'm not sure, if you understood me right. Yes, it's about collision response (I know the word now :)). But it is possible, that two planes e.g. overlap on the y-axis, but still don't collide. Imagine two planes positioned beneath each other, with slightly different y-values and enough distance on the x-axis.
Your code would detect a collision?

I still think that this must be some vector-operation. Maybe projecting the vector between the two planes on the two vectors that form the collision rectangle...

Share on other sites
Emergent    982
Quote:
 Original post by grisuWhat does "sign" do?

It takes a scalar and returns a scalar. Usually, it's defined

though sometimes people just do,

or

All three definitions are the same everywhere except exactly at zero...