Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Represent a cuboid with rounded edges
| ResourceFunction["RoundedCuboid"][pmin] represents a unit cube with rounded edges and with its lower corner at pmin. | |
| ResourceFunction["RoundedCuboid"][pmin,pmax] represents an axis-aligned cuboid with rounded edges and with lower corner pmin and upper corner pmax. | 
| RoundingRadius | {0.1,0.1,0.1} | the radii of rounded edges | 
| r | use r for radii in all three directions | 
| {rx,ry,rz} | separate setting for each radius | 
A unit rounded cuboid:
| In[1]:= | ![Graphics3D[ResourceFunction["RoundedCuboid"][]]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/65153914dfe555e2.png) | 
| Out[1]= |  | 
Rounded cuboids with different sizes:
| In[2]:= | ![Graphics3D[{Yellow, ResourceFunction["RoundedCuboid"][{0, 0, 0}, {1, 3, 1}], Blue, ResourceFunction["RoundedCuboid"][{2, 1, 1}, {4, 2, 3}]}]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/3805482d1a001988.png) | 
| Out[2]= |  | 
Differently styled rounded cuboids:
| In[3]:= | ![{Graphics3D[{Pink, ResourceFunction["RoundedCuboid"][]}], Graphics3D[{Opacity[.5], ResourceFunction["RoundedCuboid"][]}], Graphics3D[{Specularity[5], ResourceFunction["RoundedCuboid"][]}]}](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/18b46d0f1b251367.png) | 
| Out[3]= |  | 
Rotated rounded cuboid:
| In[4]:= | ![Graphics3D[
 Rotate[ResourceFunction["RoundedCuboid"][], \[Pi]/3, {1, -1, 1}]]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/5c2f248dd5d6cc5c.png) | 
| Out[4]= |  | 
A rounded unit cube:
| In[5]:= | ![Graphics3D[ResourceFunction["RoundedCuboid"][{0, 0, 0}]]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/5d989594888073c5.png) | 
| Out[5]= |  | 
A rounded cuboid parallel to each axis:
| In[6]:= | ![Graphics3D[ResourceFunction["RoundedCuboid"][{0, 0, 0}, {3, 2, 1}]]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/2a74c44bc46e7b58.png) | 
| Out[6]= |  | 
Short form for a rounded unit cube cornered at the origin:
| In[7]:= | ![Graphics3D[ResourceFunction["RoundedCuboid"][], Axes -> True]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/550077f35fd89825.png) | 
| Out[7]= |  | 
Color directives specify the face colors of cuboids:
| In[8]:= | ![Table[Graphics3D[{c, ResourceFunction["RoundedCuboid"][]}], {c, {Red, Green, Blue, Yellow}}]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/21532aa2f53651c1.png) | 
| Out[8]= |  | 
FaceForm can be used to specify the styles of the faces:
| In[9]:= | ![Graphics3D[{FaceForm[Pink], ResourceFunction["RoundedCuboid"][]}]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/1df291c264c77b69.png) | 
| Out[9]= |  | 
Different properties can be specified for the front and back of faces using FaceForm:
| In[10]:= | ![Graphics3D[{FaceForm[Yellow, Blue], ResourceFunction["RoundedCuboid"][{.1, -.5, .1}, {.9, .8, .9}]}, PlotRange -> {{-1/4, 5/4}, {1/4, 5/4}, {-1/4, 5/4}}]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/3542c4dbf03a56c7.png) | 
| Out[10]= |  | 
Opacity specifies the face opacity:
| In[11]:= | ![Table[Graphics3D[{Opacity[o], ResourceFunction["RoundedCuboid"][]}, Boxed -> False], {o, {0.1, 0.5, 0.9}}]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/072cb39ba79783b8.png) | 
| Out[11]= |  | 
Decompose the cuboid into its components and apply different styling to each:
| In[12]:= | ![{faces, edges, vertices} = Rest@ResourceFunction["RoundedCuboid"][];](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/69994ab1bfe9ae1f.png) | 
| In[13]:= | ![Graphics3D[{EdgeForm[], {Opacity[.7, Orange], faces}, {Opacity[.7, Purple], edges}, Yellow, vertices}]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/3b72486658d90193.png) | 
| Out[13]= |  | 
Adjust how rounded the edges are:
| In[14]:= | ![Graphics3D[
   ResourceFunction["RoundedCuboid"][{0, 0, 0}, 2.5 {1, 1, 1}, RoundingRadius -> #], Boxed -> False] & /@ {.1, .5, 1}](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/4417b74142fce516.png) | 
| Out[14]= |  | 
Adjust the edges in each direction independently:
| In[15]:= | ![Graphics3D[
 ResourceFunction["RoundedCuboid"][{0, 0, 0}, 3 {1, 1, 1}, RoundingRadius -> {0.2, 0.3, 0.5}], Boxed -> False]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/532c6df2359d95e2.png) | 
| Out[15]= |  | 
Leave some edges sharp:
| In[16]:= | ![Graphics3D[
 ResourceFunction["RoundedCuboid"][{0, 0, 0}, 3 {1, 1, 1}, RoundingRadius -> {0.5, 0, 0.5}], Boxed -> False]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/7b4809a22d1a1ab4.png) | 
| Out[16]= |  | 
A simple 3D bar chart:
| In[17]:= | ![data = RandomReal[{1, 10}, {5, 4}];](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/1a5ea25f29c28dc7.png) | 
| In[18]:= | ![Graphics3D[
 MapIndexed[{Hue[(Last[#2] - 1)/4], ResourceFunction["RoundedCuboid"][Append[{1, 2} #2 - {.5, .5}, 0],
      Append[{1, 2} #2 + {.5, .5}, #1], RoundingRadius -> .3]} &, data, {2}], Axes -> {False, False, True}, Lighting -> "Neutral"]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/18c2992ec7d598f2.png) | 
| Out[18]= |  | 
Use Rotate to get all possible rounded cuboids in Graphics3D:
| In[19]:= | ![Graphics3D[
 Rotate[ResourceFunction[
   "RoundedCuboid"][{0, 0, 0}, {1, 2, 1}], -30 Degree, {0, 0, 1}], Axes -> True]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/01df1947a03450a6.png) | 
| Out[19]= |  | 
Rectangle with a non-zero value for RoundingRadius is a 2D version of RoundedCuboid:
| In[20]:= | ![Graphics[Rectangle[{0, 0}, RoundingRadius -> .2]]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/2bd9f6a45ab429d8.png) | 
| Out[20]= |  | 
Cuboid is a special case of RoundedCuboid:
| In[21]:= | ![{Graphics3D[{EdgeForm[], Cuboid[]}], Graphics3D[ResourceFunction["RoundedCuboid"][RoundingRadius -> 0]]}](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/32e961f84d5f5987.png) | 
| Out[21]= |  | 
Cylinder can be viewed as a special case of RoundedCuboid:
| In[22]:= | ![{Graphics3D[{EdgeForm[], Cylinder[]}], Graphics3D[
  ResourceFunction["RoundedCuboid"][RoundingRadius -> {.5, .5, 0}]]}](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/457bb5e3e18562e8.png) | 
| Out[22]= |  | 
Sphere can be viewed as a special case of RoundedCuboid:
| In[23]:= | ![{Graphics3D[{EdgeForm[], Sphere[]}], Graphics3D[
  ResourceFunction["RoundedCuboid"][RoundingRadius -> {.5, .5, .5}]]}](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/21e983f2311c645e.png) | 
| Out[23]= |  | 
BarChart3D or RectangleChart3D can be used to create rounded cuboids:
| In[24]:= | ![BarChart3D[{1}, ChartElementFunction -> ChartElementDataFunction["DoubleProfileCube", "HorizontalProfile" -> 1.7, "VerticalProfile" -> 6]]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/1ee4297287ff1953.png) | 
| Out[24]= |  | 
Get the graphical primitive for BarChart3D:
| In[25]:= | ![roundCub[pt1_, pt2_, {hprof_, vprof_}] := ChartElementDataFunction["DoubleProfileCube", "HorizontalProfile" -> hprof, "VerticalProfile" -> vprof][
  Transpose[{pt1, pt2}]]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/301585b41d84b5d6.png) | 
| In[26]:= | ![Graphics3D[roundCub[{0, 0, 0}, {1, 1, 1}, {5, 5}], Axes -> True]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/6e4ce7a88866916d.png) | 
| Out[26]= |  | 
Compare with RoundedCuboid:
| In[27]:= | ![Graphics3D[{ResourceFunction["RoundedCuboid"][{0, 0, 0}, {1, 1, 1}, RoundingRadius -> {0.25, 0.25, 0.1}]}, Axes -> True]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/5968019e66298386.png) | 
| Out[27]= |  | 
The two cuboids have a very different internal structure:
| In[28]:= | ![{
 Graphics3D[{EdgeForm[Thick], roundCub[{0, 0, 0}, {1, 1, 1}, {5, 5}]},
   Axes -> True, ImageSize -> Medium],
 Graphics3D[
  ResourceFunction["RoundedCuboid"][{0, 0, 0}, {1, 1, 1}, RoundingRadius -> {0.25, 0.25, 0.1}] /. x_EdgeForm :> EdgeForm[Thick], Axes -> True, ImageSize -> Medium]
 }](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/4c50a3ee49e910d4.png) | 
| Out[28]= |  | 
When the width of the cuboid is zero in at least one dimension, no cuboid is created:
| In[29]:= | ![Graphics3D[ResourceFunction["RoundedCuboid"][{0, 0, 0}, {1, 1, 0}]]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/18c61c778b61232d.png) | 
| Out[29]= |  | 
When any length of the cuboid is less than twice the corresponding setting for RoundingRadius, a warning is issued and artifacts appear:
| In[30]:= | ![Graphics3D[
 ResourceFunction["RoundedCuboid"][{0, 0, 0}, {1, 1, 2}, RoundingRadius -> {.1, .1, 1.7}]]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/0fd257a4860a1fd3.png) | 
| Out[30]= |  | 
Random rounded cuboid collections:
| In[31]:= | ![Graphics3D[
 Table[{EdgeForm[Opacity[.3]], Hue[RandomReal[]], Rotate[#, RandomReal[{0, 2 \[Pi]}], RandomReal[{0, 1}, {3}]] &@
    ResourceFunction["RoundedCuboid"][RandomReal[4, 3]]}, {40}], PlotRange -> {0, 7}]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/741813ff85492c3a.png) | 
| Out[31]= |  | 
Adjust interactively the rounding radii:
| In[32]:= | ![Manipulate[
 Graphics3D[{ResourceFunction["RoundedCuboid"][{0, 0, 0}, 2 {1, 1, 1},
      RoundingRadius -> {rx, ry, rz}] /. x_EdgeForm :> EdgeForm[Thick], Opacity[.5], Cuboid[{0, 0, 0} - 0.001, 2 {1, 1, 1} + 0.001]}, Boxed -> False], {{rx, 0.7}, 0, 1}, {{ry, .2}, 0, 1}, {{rz, .5}, 0, 1}]](https://www.wolframcloud.com/obj/resourcesystem/images/388/388a44cf-792e-47bf-a8b9-8005d15fb46a/492558c5849adb02.png) | 
| Out[32]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License