• Create Account

## Cylinder physics

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1smittix  Members

282
Like
0Likes
Like

Posted 16 October 2004 - 09:42 PM

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?

### #2Motorherp  Members

613
Like
0Likes
Like

Posted 17 October 2004 - 12:07 AM

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.

### #3SpaceDude  Members

208
Like
0Likes
Like

Posted 17 October 2004 - 12:12 AM

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.

### #4scgames  Members

2082
Like
0Likes
Like

Posted 17 October 2004 - 03:51 PM

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.

### #5smittix  Members

282
Like
0Likes
Like

Posted 17 October 2004 - 04:35 PM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.