Function Repository Resource:

RoundedLine

Source Notebook

Represent a polyline with rounded corners

Contributed by: Jan Mangaldan

ResourceFunction["RoundedLine"][{p1,,pn},r]

represents a rounded polyline with points pi and rounding radius r.

ResourceFunction["RoundedLine"][{{p11,p12,},{p21,},},r]

represents a collection of rounded polylines.

Details

ResourceFunction["RoundedLine"] returns a Line object, and can be used as a graphics primitive.
ResourceFunction["RoundedLine"][Line[{p1,p2,}],r] gives a rounded version of Line[{p1,p2,}].
The rounding radius must be nonnegative.
ResourceFunction["RoundedLine"] works with 2D and 3D lines.

Examples

Basic Examples (1) 

A rounded polyline:

In[1]:=
Graphics[ResourceFunction[
  "RoundedLine"][{{1., 0.}, {2., 1.}, {3., 0.}, {4., 1.}}, 0.2]]
Out[1]=
In[2]:=
Graphics3D[
 ResourceFunction[
  "RoundedLine"][{{1., 1., -1.}, {2., 2., 1.}, {3., 3., -1.}, {4., 4.,
     1.}}, 0.2]]
Out[2]=

Scope (2) 

Apply styling to a rounded polyline:

In[3]:=
Graphics[{Directive[Blue, DotDashed], ResourceFunction["RoundedLine"][Line[{{0, 0}, {2, 1}, {4, 0}}], 0.4]}]
Out[3]=

Multiple disconnected rounded polylines:

In[4]:=
s = {{0, 0}, {2, 1}, {4, 0}};
Graphics[ResourceFunction["RoundedLine"][Line[{s, s + 1}], 0.3]]
Out[4]=

Applications (2) 

Use RoundedLine with Arrow:

In[5]:=
Graphics[Arrow[
  ResourceFunction["RoundedLine"][{{0, 0}, {2, 1}, {4, 0}}, 0.6]]]
Out[5]=

Use RoundedLine with Tube:

In[6]:=
Graphics3D[
 Tube[ResourceFunction[
   "RoundedLine"][{{-1, -1, -1}, {0, 0, 1}, {1, 1, -1}}, 0.16], 0.3]]
Out[6]=

Properties and Relations (1) 

RoundedLine returns a Line object:

In[7]:=
ResourceFunction["RoundedLine"][{{0., 0.}, {1., 0.}, {0., 1.}}, 0.1] // Head
Out[7]=

Possible Issues (3) 

If there are less than two points, a plain line is returned:

In[8]:=
ResourceFunction["RoundedLine"][{{0, 0}, {1, 0}}, 1/2]
Out[8]=

No rounding is done for 180° angles:

In[9]:=
ResourceFunction["RoundedLine"][{{0, 0}, {1/2, 0}, {1, 0}}, 1/2]
Out[9]=

If the rounding radius is too large, RoundedLine may give unexpected results:

In[10]:=
Graphics[{Thick, ResourceFunction[
   "RoundedLine"][{{0., 0.}, {2., 0.}, {1.5, 1.}, {0.5, 1.}}, 0.6]}]
Out[10]=

Use a smaller rounding radius:

In[11]:=
Graphics[{Thick, ResourceFunction[
   "RoundedLine"][{{0., 0.}, {2., 0.}, {1.5, 1.}, {0.5, 1.}}, 0.3]}]
Out[11]=

Neat Examples (2) 

A rounded dragon curve:

In[12]:=
Graphics[ResourceFunction["RoundedLine"][
  AnglePath[KroneckerSymbol[-1, Range[2048]] \[Pi]/2], 0.6]]
Out[12]=

A rounded Hilbert curve:

In[13]:=
Graphics3D[
 Tube[ResourceFunction["RoundedLine"][HilbertCurve[3, 3], 0.2], 0.1]]
Out[13]=

Version History

  • 1.0.0 – 22 March 2021

Related Resources

License Information