# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Represent a cylinder-like 3D object with protrusions

Contributed by:
Jaroslav Kysela

ResourceFunction["CylindricalFlange3D"][] represents a cylinder with one protrusion. | |

ResourceFunction["CylindricalFlange3D"][ represents a graphics object of type | |

ResourceFunction["CylindricalFlange3D"][ represents an object with front protrusions specified by | |

ResourceFunction["CylindricalFlange3D"][ specifies front and back protrusions. | |

ResourceFunction["CylindricalFlange3D"][ specifies front and back protrusions, as well as protrusions along the circumference. |

ResourceFunction["CylindricalFlange3D"] can be used in Graphics3D.

ResourceFunction["CylindricalFlange3D"] in general returns a (possibly large and nested) list of graphics primitives such as Cylinder or BSplineSurface that together constitute a flange.

ResourceFunction["CylindricalFlange3D"] is intended as a convenience function that allows for easy creation of composed cylinder-like graphics objects with textual labels. Its purpose is purely visual, no computation with the output (such as RegionMeasure) is supported.

The first argument specifies the shape and size of the main graphics object, the other arguments specify the front and back protrusions and the protrusions along the circumference, respectively.

The first argument, *type*, can take any of the following forms:

Automatic | default shape is set to "Cylinder" |

shapename | string specifying the shape, see below |

{shapename,length} | specify the length of the body (default is 0.4) |

{shapename,length,rad} | specify the (outer) radius (default is 1) |

{shapename,length,rad,pars} | specify additional parameters such as rounding radii (if any exist) |

Parameter *shapename* can take on the following forms:

"Annulus3D" | object given by ResourceFunction["Annulus3D"] |

"Cylinder" | object given by Cylinder |

"Empty" | no object created |

"RoundedAnnulus3D" | object given by ResourceFunction["RoundedAnnulus3D"] |

"RoundedCylinder" | object given by ResourceFunction["RoundedCylinder"] |

fun[len,rad,pars] | object generated by a pure function |

For named shapes, the input parameters are checked for whether they lie in the allowed range. When a pure function is supplied instead, no parameter preprocessing is performed.

The second, third, and fourth arguments can be of the following forms:

num | integer number num of evenly distributed protrusions on a given face |

posspec | list of protrusions' positions specified in the plane of the face (for front and back face) or along the surface of the circumference |

{posspec,shapespec} | specify both the positions as well as the shape of the protrusions, see below |

The position specification *posspec* for protrusions can have the following forms:

num | non-negative number of protrusions, evenly distributed on the face |

{{rad1,th1},{rad2,th2},…} | list of polar coordinates for individual protrusions |

{{rad1,th1,em1},{rad2,th2,em2},…} | together with the position also specify for each protrusion how much it should protrude from the surface |

The meaning of the polar coordinates is slightly different for front and back faces on the one hand, and for the circumference on the other hand. For the former, the first coordinate denotes a relative radial position of the protrusion on the face, while for the latter, the first coordinate specifies the relative position with respect to the center plane cutting through the main body. The meaning of the second and third coordinates is the same for all three faces. Namely, the second coordinate defines the angular position along the face and the third coordinate characterizes how much the protrusion sinks into the surface or protrudes from it.

The shape specification *shapespec* for protrusions follows exactly the shape specification for the main body. The allowed shapes are, however, slightly different:

"Annulus3D" | object given by ResourceFunction["Annulus3D"] |

"Cuboid" | object given by Cuboid |

"Cylinder" | object given by Cylinder |

"RoundedAnnulus3D" | object given by ResourceFunction["RoundedAnnulus3D"] |

"RoundedCuboid" | object given by ResourceFunction["RoundedCuboid"] |

"RoundedCylinder" | object given by ResourceFunction["RoundedCylinder"] |

fun[len,rad,pars] | object generated by a pure function |

The following full specifications for each shape are allowed:

{"Cylinder",len,rad} | cylinder of length len and radius rad |

{"Empty",len,rad} | empty cylinder-like object of given length and radius |

{"Annulus3D",len,rad,inrad} | 3D annulus with inner radius inrad |

{"Cuboid",z,hx,hy} | cuboid with length z, half-width hx, and half-depth hy |

{"RoundedCylinder",len,rad,rrad} | rounded cylinder with rounding radius rrad |

{"RoundedAnnulus3D",len,rad,inrad,rrad} | rounded 3D annulus with inner radius inrad and rounding radius rrad |

{"RoundedCuboid",z,hx,hy,rrad} | rounded cuboid with rounding radius rrad |

When only a partial shape specification is given, default values are used instead. The default value for *len* is 0.4 for the main body and 0.2 for protrusions; for *rad* it is 1 for body and 0.1 for protrusions. Additional parameters are dynamically calculated from the values of these two parameters (if not supplied explicitly). The inner radius *inrad* and rounding radius *rrad* are set to 0.5*rad* and 0.01*rad*, respectively. For "Cuboid" and "RoundedCuboid" *z* is set to *len*, while *hx* and *hy* are set to *rad*.

The following options can be given:

"Label" | None | textual label on the main object |

PlotPoints | 20 | resolution of the cylindrical mesh underlying the label |

RasterSize | 200 | raster size of each label |

"RotateProtrusions" | Automatic | whether to rotate the front and back protrusions |

Textual labels specified by "Label" are represented as rasterized images wrapped in Texture that spans a mesh created by RevolutionPlot3D.

The "Label" setting can have the following forms:

None | Automatic | no label |

"SomeText…" | text of the label |

Style[stylespec] | text wrapped in Style |

{textspec,scale} | specify also a scale (default scale is 1) |

{textspec,scale,orientation} | specify orientation (can be any real number, default is 0) |

The "RotateProtrusions" setting can have the following forms:

Flange with five "rivets":

In[1]:= |

Out[1]= |

Wheel on a shaft:

In[2]:= |

Out[2]= |

Gear:

In[3]:= |

Out[3]= |

Collar with a label:

In[4]:= |

Out[4]= |

Customize the shapes:

In[5]:= |

Out[5]= |

By default, create a cylinder with one protrusion:

In[6]:= |

Out[6]= |

Specify the shape of the body:

In[7]:= |

Out[7]= |

Supply custom-made pure function to define the shape:

In[8]:= |

Out[8]= |

"Turn off" the body and keep only the protrusions:

In[9]:= |

Out[9]= |

Specify the length and the radius of the body:

In[10]:= |

Out[11]= |

Specify additional parameters such as the rounding radius:

In[12]:= |

Out[12]= |

Specify the number of front and/or rear protrusions:

In[13]:= |

Out[13]= |

Instead of the number, specify the relative polar coordinates in the plane of the base:

In[14]:= |

Out[14]= |

Optional third coordinate specifies how the protrusion sinks into the base:

In[15]:= |

Out[15]= |

Specify the shape of the protrusions:

In[16]:= |

Out[16]= |

Custom-made shape supplied as a pure function:

In[17]:= |

Out[17]= |

Specify the length, radius, and additional parameters of protrusions the exact same way as for the main body:

In[18]:= |

Out[18]= |

The coordinates and the detailed shape specification can be supplied simultaneously:

In[19]:= |

Out[19]= |

Specify the number of "teeth" along the circumference:

In[20]:= |

Out[20]= |

Specify their positions instead:

In[21]:= |

Out[21]= |

The first coordinate specifies the relative position along the revolution axis, the second coordinate the azimuthal angle:

In[22]:= |

Out[22]= |

Optional third coordinate specifies how much the protrusions sink into the main body:

In[23]:= |

Out[24]= |

Specify the shape of the teeth:

In[25]:= |

Out[25]= |

The detailed specification of the tooth shape follows that for front and rear protrusions:

In[26]:= |

Out[31]= |

The shape can also be specified as a pure function:

In[32]:= |

In[33]:= |

Add a textual label to the body:

In[34]:= |

Out[34]= |

Add styling:

In[35]:= |

Out[35]= |

Modify the size of the label:

In[36]:= |

Out[36]= |

Rotate the label:

In[37]:= |

Out[37]= |

Adjust the resolution of the mesh that underlies the label:

In[38]:= |

Out[38]= |

Decrease the raster size of textual labels for faster rendering:

In[39]:= |

Out[39]= |

By default, the protrusions are rotated based on their angular position:

In[40]:= |

Out[40]= |

Turn the automatic rotation off:

In[41]:= |

Out[41]= |

Address front and back protrusions separately:

In[42]:= |

Out[42]= |

Water tank with rivets:

In[43]:= |

Out[46]= |

Saturn:

In[47]:= |

Out[47]= |

Simple model of a pair of gears:

In[48]:= |

Out[48]= |

Turbine:

In[49]:= |

Out[50]= |

Multiple flanges can be composed to create more complex objects:

In[51]:= |

In[52]:= |

Text wrapped around a cylindrical surface:

In[53]:= |

Out[53]= |

Round surfaces that are internally represented by BSplineSurface may be rendered with edges:

In[54]:= |

Out[54]= |

Increase the sampling rate for splines in Graphics3D:

In[55]:= |

Out[55]= |

The textual label may contain rasterization artifacts:

In[56]:= |

Out[56]= |

Increase the rasterization rate of the label and/or the number of points of the underlying mesh:

In[57]:= |

In[58]:= |

Custom shapes have to be supplied as pure functions, i.e. with head Function:

In[59]:= |

Out[60]= |

In[61]:= |

Out[62]= |

3D art:

In[63]:= |

Out[63]= |

In[64]:= |

In[65]:= |

Simple clockwork:

In[66]:= |

Out[67]= |

Wolfram Language 13.0 (December 2021) or above

- 1.0.0 – 28 June 2023

This work is licensed under a Creative Commons Attribution 4.0 International License