Ball to egde/hole collision Detection and response
Does anyone know a good sph开发者_开发百科ere to hole collision detection and response algorithm in 3D? I have spent a lot of time googling with no success. The hole is a square of side 2units.Sphere diameter=3units. The hole is axis aligned. There is gravity and friction .Any help would be much appreciated.
Clarification: I'm assuming the "hole" means a square on infinite plane extruded orthogonal to the plane, thus forming concave shape. From your question it's not clear if it may be, say, a thin wire square in space (it'd be easier to detect collision). The 3-unit sphere can't go through 2-unit square (assuming 2 unit is the length of the square side), did you mean 4-unit square? With a perfect 2-unit square there are 3 contact configurations I can think of: 1-, 2- and 4-side contact (sphere at the edge, in the corner, and resting on all 4 sides since it's bigger than the hole). The sphere can never touch the inside walls of the hole, just the edges. There are no convex vertices here, so it can't really touch the vertices in a meaningful manner (resting on a vertex of the square will yield the same response as resting on the plane; it's also a degenerate case of resting in the corner when both corner contacts are the same point).
Also, I'm assuming you want continuous collision detection with the sphere starting in a valid configuration (non-penetrating). It's a little tricky to find good contacts if the sphere is penetrating the hole in the corner and you want graceful recovery from penetration, so your best bet as the first solution is not to let it penetrate.
I believe you didn't find the collision detection algorithm in google because this configuration is not general enough to be of interest for researchers. Since the hole is a simple but concave shape, the most efficient collision detection algorithm would be to sweep the sphere against ever edge of the hole (square) and against the plane.
Let's say sphere moves from point p0 with the velocity v0. The plane is the XZ plane (y=0) and the square has vertices (-1,0,-1),(1,0,-1),(1,0,1),(-1,0,1).
To sweep against the plane , just find time t such that v.y=1.5 (radius of the ball) The contact point c will be p0+v0*t+(0,-1.5,0). If that contact point is within the hole square (i.e. |c.x|<1, |c.z|<1), then continue your sweep - the ball is going to touch the hole edges. Otherwise compute collision response with normal (0,1,0) - the plane normal.
To sweep against any edge, you sweep against the infinite line that forms that edge, i.e. find time t such that the distance from the center of the ball (p0+v0*t) to the line equals the ball radius. If your segment has ends a and b and normal direction d=(b-a)/|b-a|, you can find ball center projection onto the line : ((center-a),d)*d+a. If the projection is on the segment (i.e. projection is between 0 and |b-a|), then the ball touches the line.
In your case, you don't have to sweep the ball against the segment ends, but generally you have to do that for any convex corner of any shape you thus sweep against.
I'm sure you can find plenty of papers about collision response online. In the simplest case, it's frictionless response, where the general idea is to find an impulse acting along the collision normal that will prevent penetration of the ball into the collision point. Then you can add some impulse beyond that to make it bouncy. The response is limited by energy and momentum conservation principles. In case of a collision response with friction, look up the coloumb friction response. You'll find that the response impulse is constrained to a cone in this case and there are variations as to how to compute the response, sometimes with paradoxical results (look up Painlevé paradox).
Phew, this was longer than planned. I hope it'll help somebody. Over and out.
精彩评论