# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Represent a cuboid-like 3D object with protrusions

Contributed by:
Jaroslav Kysela

ResourceFunction["CuboidalFlange3D"][] represents a cube with one protrusion. | |

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

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

ResourceFunction["CuboidalFlange3D"][ specifies protrusions for individual faces. | |

ResourceFunction["CuboidalFlange3D"][ specifies protrusions for specific faces. |

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

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

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

The first argument specifies the shape and size of the main graphics object, the second argument specifies the position and shape of protrusions.

First argument can be of the following forms:

Automatic | default shape is set to "Cuboid" |

shapename | string specifying the shape, see below |

{shapename,hlen} | specify half the length of the body (default is 1) |

{shapename,hw,hlen} | specify half the width and height (default is 1) |

{shapename,hw,hh,hlen} | specify half the heigth separately from the width (default is 1) |

{shapename,hw,hh,hlen,pars} | specify additional parameters such as rounding radii (if any exist) |

Parameter *shapename* can be of the following forms:

"Cuboid" | object given by Cuboid |

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

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

"Empty" | no object created |

fun[hw,hh,hlen,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, no parameter preprocessing is performed.

Second argument can be of the following forms:

num | number of evenly distributed protrusions on the front face |

posspec | list of protrusion positions specified in the plane of the front face |

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

{spec1,spec2,…} | list of as many as six specifications for individual faces, each of which is of any of the forms in the previous lines |

<|k1→spec1,k2→spec2,…|> | Association where keys specify the positions of faces to which the specifications apply |

When the second argument is specified as an Association, it can be of two distinct forms:

<|num1→spec1,num2→spec2,…|> | specify faces based on their numerical index, e.g. <|3→{2,"Cylinder"},5→5|> creates two cylindrical protrusions on the third face and five cuboidal protrusions on the fifth face |

<|Left→spec1,Right→spec2,…|> | specify faces based on their relative position, the example above would correspond to <|Above→{2,"Cylinder"},Right→5|> |

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

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

{{x1,y1},{x2,y2},…} | list of Cartesian coordinates for individual protrusions |

{{x1,y1,em1},{x2,y2,em2},…} | together with the position also specify for each protrusion how much it should protrude from the surface |

The Cartesian coordinates are relative with 0 correspoding to the center, 1 for one corner of the main body, and -1 for the opposite corner. 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 with the only difference that the second parameter corresponds to the full length, not just half the length. The allowed shapes are, also, slightly different:

"Cylinder" | object given by Cylinder |

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

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

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

"Cuboid" | object given by Cuboid |

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

fun[hw,hh,hlen,pars] | object generated by a pure function |

The following full specifications for each shape are allowed:

{"Cylinder",rad,hlen} | cylinder of half-length hlen and radius rad |

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

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

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

{"Empty",hx,hy,hz} | empty cuboid-like object of given dimensions |

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

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

{"RoundedFrame3D",hx,hy,hz,tx,ty,rrad} | rounded 3D frame with thicknesses tx and ty, and with rounding radius rrad |

When only a partial shape specification is given, default values are used instead. The default value for *hx*, *hy*, and *hz* is 1 for the main body and 0.1 for protrusions. Additional parameters are dynamically calculated from the values of *hx*, *hy*, and *hz* (if not supplied explicitly). The thicknesses *tx* and *ty* for "RoundedFrame3D" are set to 0.3*hx* and 0.3*hy*, respectively. The inner radius *inrad* and rounding radius *rrad* are set to 0.5*hx* and 0.01*hx*, respectively. For "Cylinder", "RoundedCylinder", "Annulus3D", and "RoundedAnnulus3D" *rad* is set to *hx*, while *hlen* is set to *hz*. Also, for protrusions the value of *hz* (or *hlen*) corresponds to the entire length, whereas for the main body it is only half the length.

The following options can be given:

"Label" | None | textual label(s) on the main object |

RasterSize | 200 | raster size of each label |

"RotateProtrusions" | Automatic | whether to rotate the protrusions |

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

The "Label" setting can have the following forms:

None | Automatic | no label |

"SomeText…" | textual label on the front face |

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) |

{labspec1,labspec2,…} | specify labels for individual faces, not just the front face |

<|k1→labspec1,k2→labspec2,…|> | specify for specific faces, the form of keys is the same as for protrusions |

The RasterSize setting can have the following forms:

num | the same size for all labels |

{num1,num2,…} | specify sizes for each label |

<|k1→num1,k2→num2,…|> | specify sizes for specific labels, the form of keys is the same as for protrusions |

The "RotateProtrusions" setting can have the following forms:

True|False | specify whether the protrusions are rotated for all faces |

Automatic | equivalent to False for types "Cylinder", "RoundedCylinder", "Annulus3D", and "RoundedAnnulus3D", and to True otherwise (default) |

{rotspec1,rotspec2,…} | specify individually for each face |

<|k1→rotspec1,k2→rotspec2,…|> | specify for specific faces, the form of keys is the same as for protrusions |

When "RotateProtrusions" is active, the protrusions for a given face are rotated in such a way that they point to the center of the face.

Flange with four "rivets":

In[1]:= |

Out[1]= |

Cuboid with a "button":

In[2]:= |

Out[2]= |

Dice with numbered faces:

In[3]:= |

Out[3]= |

3D frame with a textual label:

In[4]:= |

Out[4]= |

Customize the shapes:

In[5]:= |

Out[5]= |

By default, create a cuboid 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, width, and height of the body:

In[10]:= |

Out[11]= |

Specify additional parameters such as the rounding radius:

In[12]:= |

Out[12]= |

Specify the number of protrusions:

In[13]:= |

Out[13]= |

Instead of the number, specify the relative Cartesian 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, width, height, 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 protrusions for the bottom face:

In[20]:= |

Out[20]= |

Specify protrusions for all the faces:

In[21]:= |

Out[21]= |

Set protrusions only for the "fourth" face using three equivalent ways:

In[22]:= |

Out[22]= |

Specify protrusions for multiple faces:

In[23]:= |

Out[23]= |

Add a textual label to the body:

In[24]:= |

Out[24]= |

Add styling:

In[25]:= |

Out[25]= |

Modify the size as well as the rotation of the label:

In[26]:= |

Out[26]= |

The default size of the rotated label is automatically adjusted to fit into the face:

In[27]:= |

Out[27]= |

Specify labels for other faces using either a List of an Association:

In[28]:= |

Out[28]= |

Use symbolic names:

In[29]:= |

Out[29]= |

The names are aligned with the "eponymous" ViewPoint settings:

In[30]:= |

Out[6]= |

Adjust the raster size for all labels:

In[31]:= |

Out[31]= |

Adjust each label separately, Association is also supported:

In[32]:= |

Out[32]= |

By default, the protrusions are rotated such that they point towards the face center:

In[33]:= |

Out[33]= |

Turn the automatic rotation off:

In[34]:= |

Out[34]= |

Address individual faces separately:

In[35]:= |

Out[35]= |

Specification with Association is supported and follows closely the one for protrusions:

In[36]:= |

Out[36]= |

Simple model of a camera:

In[37]:= |

Out[37]= |

Simple model of a control panel:

In[38]:= |

Out[39]= |

Water tank with rivets:

In[40]:= |

Out[41]= |

Cage:

In[42]:= |

Out[43]= |

Star:

In[44]:= |

Out[44]= |

Multiple flanges can be composed to create more complex objects:

In[45]:= |

Out[45]= |

Text wrapped around a rectangular surface:

In[46]:= |

Out[47]= |

The length parameter for the body is half the resulting length, but not so for the protrusions:

In[48]:= |

Out[49]= |

The textual label may contain rasterization artifacts:

In[50]:= |

Out[50]= |

Increase the rasterization rate of the label:

In[51]:= |

Out[51]= |

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

In[52]:= |

Out[36]= |

In[53]:= |

Out[54]= |

When two parameters {*w*,*l*} are supplied, they are internally expanded into {*w*,*w*,*l*} and the form of Function has to reflect it:

In[55]:= |

Out[55]= |

3D art:

In[56]:= |

Out[57]= |

In[58]:= |

In[59]:= |

Wolfram Language 13.0 (December 2021) or above

- 1.0.0 – 26 June 2023

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