# Howto handle edge-edge collison (2D)

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

## Recommended Posts

Hello together, So far, my 2D physik engine works pretty good. I handle edeg-edge collision the following way: I have 2 contact points (begining and end of contact-edge). I take a third point directly in the middle. For all those 3 points I calculate the change of angular and linear velocity what they would cause if a vertex-edge collision would happen here. Than I average those 3 values and apply the average. So far so good, now what is happening: I have some object lying on a big ground (gravity is on). Elasticity is set to 0: ______________________________________ ___________*************______________ ###################################### ___________^_____^_____^______________ ___________a_____b_____c______________ *=object #=ground ^=contact points for calculation. The object rotates just a little bit. The following cycly keeps happening: 1. The object collides a couple of times with the ground on point "a" in a vertex-edge collision and is gaining rotational speed to the left. 2. The object collides a couple of time in a edge-edge collision with the ground. Rotational speed is changed minmal (maybe 1/5 of what it got in step 1). 3. The object rotates so far, that it now collides in a edge-vertex collison at "c" and is gaining rotational speed to the right. The process begins at step 1 in oposite direction. This causes the object to always move little when it should be still (especially beacause elasticity is set to 0). Any thoughts for a solution? How do you handle edge-edge collision? Thanks! Nathan

##### Share on other sites
ususally, edge-edge collision is not done in 2d, like how you dont do tri-tri collision in 2d: there simply is no need, and things can be solved more elegantly using just vertex-edge collisions.

however, that does not really seem to be your problem. it would seem a little damping is in order. you might be saying elasticiy is 0", so there already is maximum damping, but appearently that didnt really work out if i read this: "1. The object collides a couple of times with the ground on point "a" in a vertex-edge collision and is gaining rotational speed to the left."

it would seem you handle contacts with penalty forces, so youll need damping for it to settle down.

##### Share on other sites
I do not know what "penalty forces" are, I do collision detecting with calculating the resulting impulse.
Elasticity is definitly set to 0, but it makes sence that a collision at "a" makes the object rotate left. Elasticity of 0 just means that after the collision the object and the ground do not relativly move at the contact point in normal direction. And they do not after collision: The object rotates left AND moves a little down. That is what happens in the real world too in such a case.
Edit: You do not do edge-edge collision in 2d? Can you explain?

##### Share on other sites
I also don't do edge-edge collision in my 2d engine and it seems
to work just fine that way.

If you want an explanation how to implement edge egdge collision
anyhow look here.

##### Share on other sites
But hey! If you don't do edge-edge collision there'll be a big problem (one that I'm currently facing in my engine):

Imagine a box dropping on the floor:

|-----|
|-----|
|-----|

---------------
| |

Now suddenly in one timestep you'll find the two lower points of the box "inside" the ground-box. So doing my vertex-edge stuff I take one of those points and apply an impulse there. In result the box gets a very high angular velocity and rolls to the left (or right).
Of course you'd rather expect it NOT to rotate and simple bounce upwards...but that can only be done by

a) Consider all points involved in the collision
(Complicated! what if they aren't all at the same penetration depth? Did they collide at the same time? Maybe on of them doesn't count because it arrived later than the other points? etc..)

How would this be handled correctly?

##### Share on other sites
Quote:
 Original post by LonelyStarThanks for your reply Eelco.I do not know what "penalty forces" are, I do collision detecting with calculating the resulting impulse.Elasticity is definitly set to 0, but it makes sence that a collision at "a" makes the object rotate left. Elasticity of 0 just means that after the collision the object and the ground do not relativly move at the contact point in normal direction. And they do not after collision: The object rotates left AND moves a little down. That is what happens in the real world too in such a case.Edit: You do not do edge-edge collision in 2d? Can you explain?

yeah i see your problem, vankurt also touched on this.

if you have multiple contacts, you cant just solve them one at a time. constraining the normal velocity at one point will likely violate the constaint somewhere else again. the real solution to this is solving for multiple contact points at the same time, but this is not something youre likely to pull off even if you were to work on it for a month. you can approximate solving for the contact impulses simulationiously however, by keeping a list of the contacts, and iterating over them a bunch of times, and youre likely to converge to the desired result.

edge-edge collision doesnt solve this problem. it only complicates things, and if you managed to solve the simple box case to a statisfying degree with it: what about an object that touches the ground with two edges? youre back at the same problem again.

##### Share on other sites
Well, in nearly all cases (even if edges are as parallel as possible, them will not be truly parallel because of inaccuracies), you have edge-vertex collisions only. In perfect case of collision of 2 exactly parallel edges (REALLY rare case), you will have at least two vertex-edge collisions AND at least one edge-edge collision. (Edge-edge aren't adding any useful forces). By considering edge-edge collisions, you can only make whole thing work even worse in these rare special cases.

As on problem, as Eelco said, it is problem of multiple contacts
For example, you'll get exactly same problem in this case:
_______________________\  __________________  / \/                  \/-----------------------------------

when you have simultaneous vertex-edge collisions (and don't have anything looking like edge-edge).

1. 1
Rutin
68
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 21
• 10
• 33
• ### Forum Statistics

• Total Topics
633438
• Total Posts
3011881
• ### Who's Online (See full list)

There are no registered users currently online

×