retrosnob
retrosnob

Reputation: 113

Clarification of collisions in pymunk

I've been investigating Pymunk as a possible platform for a spatial chemistry simulation. I naively thought that when two shapes collide there would be a single contact point. In fact that can be up to two contact points. I also find that each contact point has two points, point_a and point_b. The documentation says

point_a and point_b are the contact position on the surface of each shape

I wonder if someone less naive than I am could explain:

Thanks.

Upvotes: 1

Views: 269

Answers (1)

viblo
viblo

Reputation: 4603

Im dont know enough of the collision algo to answer from the mathematical background, but I can give some help on the way:

  1. This is from the collision algorithm used. For easy (e.g. Circle to circle) collisions only one point is found, as you can see here: https://github.com/slembcke/Chipmunk2D/blob/master/src/cpCollision.c#L526 In more advanced cases, e.g. Poly to Poly, then the GJK & EPA algorithms are used, https://github.com/slembcke/Chipmunk2D/blob/master/src/cpCollision.c#L607 and this can produce one or two points.

  2. I think the reasoning is shown in the below picture. The points are located on each shape, and since they can be overlapping it becomes natural with one for each.

enter image description here

  1. I suspect so, but am not 100% sure.

If you are intersted about the GJK & EPA implementation, there's a intro blog post from when it was first introduced into Chipmunk here: http://howlingmoonsoftware.com/wordpress/enhanced-collision-algorithms-for-chipmunk-6-2/

Upvotes: 1

Related Questions