2d polygon collisions maths... headache

BlitzMax Forums/BlitzMax Programming/2d polygon collisions maths... headache

Nate the Great(Posted 2009) [#1]
hi

so I have been working on my verlet-based physics engine verlet max for quite some time now and the entire project has reached a standstill because of this one problem. I keep trying to implement some sort of polygon-polygon collisions but it never seems to work right. I was thinking about giving up but I decided to post here first.

I have looked at engines like farseer and box2d and nonophysics to see how they do it but the maths in those are uncommented and too spread out to understand. So does anyone know any good fast solid methods for polygon-polygon collision response...

btw I am not interested in Seperating axis theorom as I need this to work with all shapes convex and concave.


_JIM(Posted 2009) [#2]
I' not a grand magician in physics, but can't this be solved by testing each point of one poly against the other poly, and then viceversa (to avoid possible errors)? (using that function in the code archives :-) )

If they intersect, (here's where my physics knowledge lacks) just push the intersecting points behind?


beanage(Posted 2009) [#3]
agree with Jim; test each point of TriA whether it is inside TriB, at least that would provide some basic collision checking..
PLUS this could be performed with any complex concave/convex shapes, when using a raycast inside/outside checking..
However, still got no idea how to perform the velocity/angle calculations on this.. you would have to know abou the points movement, and which particular line of TriB it intersected, but how to find out..?


Nate the Great(Posted 2009) [#4]
yeah I think I have the actual collision detection down... its just the response thats getting me... I can detect if physics objects are colliding, I just cant figure out the maths to get the physics objects out of eachother with the proper velocities etc.

I will describe it in a bit more detail I guess.

I figured every frame I should do a check to see if the verlets had gone over a constraint using a lines intersect function between the constraint and the x,y to the ox,oy of the verlet... Then I figured out I must also detect whether a constraint passes over a verlet for which I use the pointinpoly routine. These work fine for collision detection but I cant figure out the response.


matibee(Posted 2009) [#5]
These old articles are good, I don't know if you've seen them before...

http://chrishecker.com/Rigid_Body_Dynamics


Who was John Galt?(Posted 2009) [#6]
Figure out how far the point moved over the line, in a direction normal to the line, and move it back in the same direction by the distance it moved. That should stop things overlapping at least. How are you handling velocity after collision for collisions (say circle-circle) that you already have covered? I need to know so I can suggest a method to work with polys.


Nate the Great(Posted 2009) [#7]
@john Galt

that isnt the only possible way objects can overlap

suppose you have a point that has no velocity whatsoever then the constraint passes over it... then no collision is detected. so that is mainly what I am struggling with.


Who was John Galt?(Posted 2009) [#8]
Good point... now you've got me scratching my head. Are these points always connected to lines?


Nate the Great(Posted 2009) [#9]
not always... I mean this is a general purpose physics engine so I have to prepare it for any situation like this...


matibee(Posted 2009) [#10]
Here's what I think you should be doing, although I've never coded a physics engine so.. ;)

Even if your vertlet has no velocity, you should be checking for penetration/overlaps with every vertlet that's close (your spacial partitioning should decide) to your polygon. Then I assume you'd rewind the time-step to the point at which the penetration occured and exchange the necessary forces between poly and vertlet.

This is no different to any other primitive-primitive collision where an edge hits a corner or vice-versa.

Also, perhaps you'll have to be careful how far you go with vertlets as once they're above a small point size they should be treated as circlular primitives(?)

Nice work on the demo's, makes me want to do 2d physics again :)


Nate the Great(Posted 2009) [#11]
ok thanks that is kinda what I was thinking earlier but I thought it may be a bit slow... so your suggesting like I move the objects half a time step back then if they are still colliding, I move it another half of a half of a timestep back but if they are not colliding, I would move it half of a half of a timestep forward...

Nice work on the demo's, makes me want to do 2d physics again :)


demos?

edit: oh are you talking about the ones in my sig link?