• Advertisement
Sign in to follow this  

Plane Collision Detection

This topic is 2925 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Hi,

Thanks for your reply.

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 this post


Link to post
Share on other sites
Quote:
Original post by grisu
What does "sign" do?


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

\mathrm{sign}(x) = \left\{ \begin{array}{rcl} 1 & \mathrm{~if~} & x > 0 \\ 0 & \mathrm{~if~} & x = 0 \\ -1 & \mathrm{~if~} & x < 0 \end{array} \right.
though sometimes people just do,

\mathrm{sign}(x) = \left\{ \begin{array}{rcl} 1 & \mathrm{~if~} & x > 0 \\ -1 & \mathrm{~if~} & x \leq 0 \end{array} \right.
or

\mathrm{sign}(x) = \left\{ \begin{array}{rcl} 1 & \mathrm{~if~} & x \geq 0 \\ -1 & \mathrm{~if~} & x < 0 \end{array} \right.

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement