Jump to content
  • Advertisement
Sign in to follow this  
1101

Capsule based collisions?

This topic is 2905 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

Okay until now I have used spheres to fill the volume of various objects in order to handle collisions. But I would like to instead use capsules (pills) because they can better fill the volume of say a rectangular box. But I'm wondering three things.

1) How do I actually tell if two capsules have collided with each other? Obviously spheres collide if the distance between them is less than or equal to their radii added together.

2) How do I calculate the point of collision between two capsules, each capsule has an x,y,z value as well as a radius and length value. Now obviously being 3d capsules can collide in several ways, ie an overlapping volume, a tangent point, or a curve. Now by point of collision I mean if two capsules touch at only one point then that point would be the point of collision. If they overlap a little then the middle of the volume of overlap would be the collision point. If they overlap completely then the center of either capsule should be the collision point.

Here is how I calculate the point of collision between spheres:
x_collision = ((radius_2*x1 + radius_1*x2)/(radius_1 + radius_2));
y_collision = ((radius_2*y1 + radius_1*y2)/(radius_1 + radius_2));
z_collision = ((radius_2*z1 + radius_1*z2)/(radius_1 + radius_2));

3) How do I calculate the amount of overlap between the two capsules? By overlap I do not mean the volume of overlap but rather some scaler that is proportional to how much they intersect. For spheres I have been taking the sum of their radii minus the distance between them. But given how capsules are not uniformly shaped this wouldn't work.

Share this post


Link to post
Share on other sites
Advertisement
You can actually generalize the methods you're using for spheres to capsules (and to a number of other shapes as well).

Both spheres and capsules fall into the category of shapes formed from all points within a given distance of specified shape. For example, spheres are comprised of all points within a given distance of a point, capsules are comprised of all points within a given distance of a line segment, and so-called 'lozenges' are comprised of all points within a given distance of a rectangle.

To determine whether two such shapes intersect, how much they overlap, and where the intersection point (or 'average' intersection point) is, it's sufficient to compute the closest pair of points on the medial structures of the two shapes; you can then derive the desired intersection info from these two points.

You're already doing this with spheres; it's just that the 'compute the closest points' part is trivial. With capsules, it's a little less trivial, but is still fairly easy; just Google/search for 'closest points on two lines' and you should find some good references.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!