Sign in to follow this  
bengaltgrs

Cylinder physics

Recommended Posts

I am trying to write a few collision detection methods for a game and I was wondering if there was an easy equation to check coliision for a cylinder than checking every single vertex of the mesh. I understand checking spheres and boxes, but is there an easy equation for checking cylinders?

Share this post


Link to post
Share on other sites
It depends what you're colliding the cylinder against. However most poeple tend to use capsules (think of a swept sphere or the classic cartoon pill) since they're much quicker. This basically just comes down to checking if any point on your object is closer than the capsules radius to the capsules line segment. As for cylinders first you'll have to project the other object's extents onto the cylinder's axis. If they all lie outside the cylinders length then no collision. If they all lie inside the cylinders length then you can use the capsule test since the cylidners flat caps won't be involved. However if some lie in and some lie out then you'll have to start checking line segments of the object against the circle which is the cylinders cap. Sorry if this isn't too clear but its not easy to explain in a limited space and without pictures. Bottom line though is if you can get away with capsules, do so. The other trick some people use to model cylinders is to use several boxes layered ontop of each other but rotated around the 'cylinders' axis at equal intervals. The more boxes you use the better the representation but the more costly it is to collide.

Share this post


Link to post
Share on other sites
for Sphere - Cylinder:

http://astronomy.swin.edu.au/~pbourke/geometry/pointline/

for Cylinder - Cylinder:

http://astronomy.swin.edu.au/~pbourke/geometry/lineline3d/

You'll need to think up some code for adding ends caps yourself but this is a good start.

Share this post


Link to post
Share on other sites
There's also an article in one of the GPG books about cylinder frustum culling that I imagine has good cylinder/plane code in it. But basically, unless you're doing something fairly simple, like an FPS where you're always aligned to the same axis, cylinders are kind of a pain for collision detection. Spheres, capsules, OBBs and ellipsoids (except with each other) are all easier.

Share this post


Link to post
Share on other sites
Thanks for all the input. The reason for knowing cylinder was basically that I was planning to write a simple physics engine that could accurately roll a barrel down a hill. It sounds like capsules would be the best way to go about doing this so I will look into that more and see what I can find. Thanks again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this