Shaping a world as a Cylinder

Post Reply
amireh
Posts: 5
Joined: Wed Mar 16, 2011 1:48 pm

Shaping a world as a Cylinder

Post by amireh »

Hello, I'm very new to Bullet and 3D physics in general, and what I'm trying to do is rather simple but I can't figure out the API.

I have a sphere that will be confined within a tunnel, which I thought could be represented as a cylinder. The constructor for the cylinder shape allows for passing in "halfExtents" which I don't understand. I expect to specify a radius of the cylinder, its length, and which axis it grows along (which I figured out by finding 2 other versions of the class, for X and Z).

I tried playing with the parameters of the constructer to see what they affected, but it wasn't helpful. How can I create a static cylinder with a specific radius and length that can "contain" rigid bodies?

Thank you!
--
PS: I'm sure I'm missing something big here, and this is probably a newb question. To my credit, I've read the manual 3 times over, and all the Wiki entries, I still don't get it.
proof
Posts: 18
Joined: Tue Mar 01, 2011 11:00 pm

Re: Shaping a world as a Cylinder

Post by proof »

Code: Select all

halfExtends = btVector3(height, radius, radius);
I don't think you can represent a tunnel with a cylinder, because it looks at the cylinder like a closed mesh... You should probably use a triangle mesh.
amireh
Posts: 5
Joined: Wed Mar 16, 2011 1:48 pm

Re: Shaping a world as a Cylinder

Post by amireh »

Thank you for your insight and suggestion, I will try it out now and will post my results! :D
Vytas
Posts: 3
Joined: Wed Nov 16, 2011 4:09 am

Re: Shaping a world as a Cylinder

Post by Vytas »

proof wrote:

Code: Select all

halfExtends = btVector3(height, radius, radius);
I too am confused about what a halfExtend is. What is the second radius value for? A cylinder should only need a height and a single radius.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm
Contact:

Re: Shaping a world as a Cylinder

Post by dphil »

In general, half extents refer to half the dimensions of the object along the x, y, and z axes. For example, a cube with half extents (0.5,0.5,0.5) will have a size of 1x1x1. As for a cylinder, I assume the last value (the second radius) is the radius along the z direction (imagine the circular end of a cylinder on the y-z plane; you can give it a y size independent of the z size to be an oval shape instead of a circle). But of course, if you want a standard (circular) cylinder, you would give the two radii the same value. Granted, I'm not sure btCylinderShape supports non-circular cylinders (it probably doesn't), in which case I imagine it might just ignore the 3rd value you pass in (still, probably best to keep the two radii the same).
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Shaping a world as a Cylinder

Post by mi076 »

half extends describe a cylinder's bounding box, a quick look at the class might clarify it rather fast...
http://bulletphysics.com/Bullet/BulletF ... Shape.html
the class stores just one radius, so regular cylinder is assumed, it is not enought data to describe oval or whatever else.. (anyway the shape may work somehow)

Code: Select all

         virtual btScalar getRadius() const
         {
                 return getHalfExtentsWithMargin().getX();
         }
Last edited by mi076 on Thu Nov 17, 2011 2:30 am, edited 1 time in total.
Vytas
Posts: 3
Joined: Wed Nov 16, 2011 4:09 am

Re: Shaping a world as a Cylinder

Post by Vytas »

Thank you, that matches my experimentation which showed that the third value had no obvious impact on the shape. I was afraid there was some non-visual impact (because the cylinder is not following proper physics in its motion -- but that is a separate post).
Evan407
Posts: 22
Joined: Sun Jan 17, 2016 2:37 am

Re: Shaping a world as a Cylinder

Post by Evan407 »

I know this thread is old but I too was searching about this and wanted to note that this is incorrect for the sake of miss information
proof wrote:

Code: Select all

halfExtends = btVector3(height, radius, radius);
I don't think you can represent a tunnel with a cylinder, because it looks at the cylinder like a closed mesh... You should probably use a triangle mesh.
the source code clarifies as follows
/*
58 cylinder is defined as following:
59 *
60 * - principle axis aligned along y by default, radius in x, z-value not used
61 * - for btCylinderShapeX: principle axis aligned along x, radius in y direction, z-value not used
62 * - for btCylinderShapeZ: principle axis aligned along z, radius in x direction, y-value not used
63 *
64 */
http://bulletphysics.com/Bullet/BulletF ... ource.html
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Shaping a world as a Cylinder

Post by Basroil »

Evan407 wrote:I know this thread is old but I too was searching about this and wanted to note that this is incorrect for the sake of miss information
Actually he was entirely correct, as a cylinder and cylinder hole are two very different beasts.
[*]How do you define the collision surface?
[*]How do you determine the penetration depth/resolution?

In both these cases the positive volume cylinder and cylinder hole are completely different. In the way Bullet currently defines a cylinder, cylinders will push out any object inside them, making them useless for a tunnel. For a tunnel shape you would need either convex decomposition (possible, though not pretty) or a triangle mesh.

If you meant the half-extent definitions, not a big issue, that information was added only a year before the last post, so it might have just been a mistake on not using the newest code. I know I've done that plenty of times :wink: More likely though, he was explaining in terms of a btCylinderX, which has "height" in x and size in y (but also same size in z, since it's not an elliptic cylinder).


Regardless, pointing it out might help others looking for answers, though maybe you should have added a bit more information about how the issue actually plays out (in terms of btCylinderX, Z, and default) :wink:
Post Reply