Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Represent a cylinder with rounded edges
| ResourceFunction["RoundedCylinder"][{{x1,y1,z1},{x2,y2,z2}},r] represents a rounded cylinder of radius r around the line from (x1,y1,z1) to (x2,y2,z2). | |
| ResourceFunction["RoundedCylinder"][{{x1,y1,z1},{x2,y2,z2}}] represents a rounded cylinder of radius 1. | 

| RoundingRadius | 0.1 | the radius of rounded edges | 
A unit radius and two units height rounded cylinder:
| In[1]:= | ![Graphics3D[ResourceFunction["RoundedCylinder"][], Axes -> True]](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/64c9c4e34269cf4d.png) | 
| Out[1]= |  | 
A rounded cylinder from the origin to {1,1,1} with radius 1/2:
| In[2]:= | ![Graphics3D[
 ResourceFunction["RoundedCylinder"][{{0, 0, 0}, {1, 1, 1}}, 1/2]]](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/097c2b595d8e71a9.png) | 
| Out[2]= |  | 
Differently styled rounded cylinders:
| In[3]:= | ![{Graphics3D[{Yellow, ResourceFunction["RoundedCylinder"][]}], Graphics3D[{Opacity[.5], ResourceFunction["RoundedCylinder"][]}], Graphics3D[{Specularity[.5], ResourceFunction["RoundedCylinder"][]}]}](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/0f6dad4a01e265fe.png) | 
| Out[3]= |  | 
Rounded cylinders with different endpoints:
| In[4]:= | ![Graphics3D[{ResourceFunction["RoundedCylinder"][], ResourceFunction["RoundedCylinder"][{{0, 3, 0}, {0, 5, 0}}, 1]}]](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/61d851b88da133f7.png) | 
| Out[4]= |  | 
Rounded cylinders with different radii:
| In[5]:= | ![Graphics3D[{ResourceFunction["RoundedCylinder"][], ResourceFunction["RoundedCylinder"][{{-1, 5, 0}, {1, 5, 0}}, 2]}]](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/60f8d46c797f6218.png) | 
| Out[5]= |  | 
Rounded cylinders with different rounding radii:
| In[6]:= | ![Graphics3D[{ResourceFunction["RoundedCylinder"][RoundingRadius -> .9],
   ResourceFunction["RoundedCylinder"][{{1, 2, 0}, {1, 5, 0}}, RoundingRadius -> .3]}]](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/45189d2a2fe3a899.png) | 
| Out[6]= |  | 
Colored cylinders:
| In[7]:= | ![Table[Graphics3D[{c, ResourceFunction["RoundedCylinder"][]}], {c, {Red, Green, Blue, Yellow}}]](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/3f5540d08392232e.png) | 
| Out[7]= |  | 
Different properties can be specified for the front and back of faces using FaceForm:
| In[8]:= | ![Graphics3D[{FaceForm[Yellow, Blue], ResourceFunction["RoundedCylinder"][]}, PlotRange -> {{-2, 2}, {-.8, 1}, {-1, 1}}]](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/0e9dbadf462dc668.png) | 
| Out[8]= |  | 
Opacity specifies the face opacity:
| In[9]:= | ![Table[Graphics3D[{Opacity[o], ResourceFunction["RoundedCylinder"][]}], {o, {0.3, 0.5, 0.9}}]](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/7d04cc6f89db9624.png) | 
| Out[9]= |  | 
Adjust how rounded the edges are:
| In[10]:= | ![Graphics3D[
   ResourceFunction["RoundedCylinder"][{{0, 0, 0}, {5, 0, 0}}, 1, RoundingRadius -> #], Boxed -> False] & /@ {.1, .5, 1}](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/660e4e5dd97d77c9.png) | 
| Out[10]= |  | 
A simple 3D bar chart:
| In[11]:= | ![data = RandomReal[{1, 3}, {10, 2}];](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/4e87077386875034.png) | 
| In[12]:= | ![Graphics3D[
 MapIndexed[{Hue[(Last[#2] - 1)/4], ResourceFunction[
     "RoundedCylinder"][{Append[{1, 2} #2, 0], Append[{1, 2} #2, #1]}, .4, RoundingRadius -> .3]} &, data, {2}], Axes -> {False, False, True}, Lighting -> "Neutral"]](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/190c59efa23ed2fc.png) | 
| Out[12]= |  | 
For small rounding radii, RoundedCylinder is effectively equivalent to Cylinder:
| In[13]:= | ![{Graphics3D[
  ResourceFunction["RoundedCylinder"][{{0, 0, 0}, {0, 0, 1}}, 1, RoundingRadius -> 0.00001]], Graphics3D[{EdgeForm[], Cylinder[{{0, 0, 0}, {0, 0, 1}}, 1]}]}](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/45530f49469d2293.png) | 
| Out[13]= |  | 
When the rounding radius is set to the cylinder radius, RoundedCylinder closely resembles CapsuleShape as well as Tube with rounded caps:
| In[14]:= | ![rad = 1;
height = 2;
{
 Graphics3D[{Blue, ResourceFunction[
    "RoundedCylinder"][{{0, 0, 0}, {0, 0, height + 2 rad}}, rad, RoundingRadius -> rad]}, PlotLabel -> "RoundedCylinder"],
 Graphics3D[{Blue, CapsuleShape[{{0, 0, 0}, {0, 0, height}}, rad]}, PlotLabel -> "CapsuleShape"],
 Graphics3D[{Blue, Tube[{{0, 0, 0}, {0, 0, height}}, rad]}, PlotLabel -> "Tube"]
 }](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/7ffbadfacf39a46e.png) | 
| Out[15]= |  | 
When the two endpoints coincide, no cylinder is created:
| In[16]:= | ![Graphics3D[
 ResourceFunction["RoundedCylinder"][{{1, 0, 2}, {1, 0, 2}}]]](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/31864a55f58c66a7.png) | 
| Out[16]= |  | 
When the rounding radius exceeds that of the cylinder, a warning is issued and artifacts appear:
| In[17]:= | ![Graphics3D[
   ResourceFunction["RoundedCylinder"][{{0, 0, 0}, {0, 0, 3}}, .5, RoundingRadius -> #]] & /@ {0.1, 0.3, 0.5}](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/0181b811656a1bd2.png) | 
| Out[17]= |  | 
| In[18]:= | ![Graphics3D[
   ResourceFunction["RoundedCylinder"][{{0, 0, 0}, {0, 0, 3}}, .5, RoundingRadius -> #]] & /@ {0.7, 0.9}](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/45e4a50459c60ca8.png) | 
| Out[18]= |  | 
When the double of the rounding radius exceeds the height of the cylinder, a warning is issued and artifacts appear:
| In[19]:= | ![Graphics3D[
   ResourceFunction["RoundedCylinder"][{{0, 0, 0}, {0, 0, 3}}, 2, RoundingRadius -> #]] & /@ {0.5, 1, 1.5}](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/057952d0579b1df4.png) | 
| Out[19]= |  | 
| In[20]:= | ![Graphics3D[
   ResourceFunction["RoundedCylinder"][{{0, 0, 0}, {0, 0, 3}}, 2, RoundingRadius -> #]] & /@ {1.7, 2}](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/0d1bd2f426019137.png) | 
| Out[20]= |  | 
Random unit rounded cylinders:
| In[21]:= | ![Graphics3D[
 Table[{EdgeForm[Opacity[.3]], Hue[RandomReal[]], ResourceFunction["RoundedCylinder"][RandomReal[10, {2, 3}], 1, RoundingRadius -> .5]}, {20}]]](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/310e5af53f3b8848.png) | 
| Out[21]= |  | 
Bouncing cylinders:
| In[22]:= | ![fB[t_, o_] := 0.5 Abs[Sin[2 \[Pi] t + o]]
fT[t_, o_] := 2 + 0.5 Sin[4 \[Pi] t + o + 4 ]](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/79053377a50f0462.png) | 
| In[23]:= | ![pos = RandomReal[{-2, 2}, {5, 4}];](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/6ef176d2efed62da.png) | 
| In[24]:= | ![Animate[Graphics3D[{{Hue[#4], ResourceFunction[
       "RoundedCylinder"][{{#1, #2, fB[t, #3]}, {#1, #2, fT[t, #3]}}, 0.5]} & @@@ pos, Darker@Brown, InfinitePlane[{0, 0, 0}, {{1, 0, 0}, {0, 1, 0}}]}, PlotRange -> {2.5 {-1, 1}, 2.5 {-1, 1}, {0, 3}}, Lighting -> "Neutral", Boxed -> False, ViewPoint -> {1.669, -2.713, 1.140}], {t, 0, 5}, AnimationRate -> .2, SaveDefinitions -> True]](https://www.wolframcloud.com/obj/resourcesystem/images/75a/75a72bb7-5d64-4179-a459-9fd3f6c4b3a0/485e3181205a0162.png) | 
| Out[24]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License