Function Repository Resource:

WiggleLine

Make a line that wiggles

Contributed by: Nik Murzin

ResourceFunction["WiggleLine"][points]

creates a Line that wiggles along a smoothed BSplineCurve derived from the given list of points.

ResourceFunction["WiggleLine"][f]

wiggles along the curve given by f.

Details and Options

Curves supported by f include BSplineFunction, BezierFunction and InterpolatingFunction expressions.
ResourceFunction["WiggleLine"] supports the following options:
"Shape""Sine"wiggle shape function or one of "Sine", "Square", "Triangle", "Sawtooth", "Helix", "Semicircles", "Braid"
"Frequency"Automaticfrequency of the wiggle
"Amplitude"Automaticamplitude of the wiggle
"TaperFraction"Automaticfraction of a line to taper off near the endpoints
"Points"Automaticnumber of line points
"Semicircles" and "Braid" shapes consist of Circle segments.

Examples

Basic Examples (2) 

Make a wiggly line between two points:

In[1]:=
Graphics@ResourceFunction["WiggleLine"][{{0, 0}, {1, 0}}]
Out[1]=

Make a curvier wiggly line:

In[2]:=
Graphics@
 ResourceFunction[
  "WiggleLine"][{{1, -3}, {0, -2}, {0, -1}, {2, -1}, {3, 0}, {1, 2}, {0, 1}}/5]
Out[2]=

Scope (1) 

Use BSplineFunction, BezierFunction or InterpolatingFunction as input:

In[3]:=
Graphics@
 ResourceFunction["WiggleLine"][
  BSplineFunction[{{1, 1}, {2, 3}, {3, -1}, {4, 1}, {5, 0}}]]
Out[3]=
In[4]:=
Graphics@
 ResourceFunction["WiggleLine"][
  BezierFunction[{{1, 1}, {2, 3}, {3, -1}, {4, 1}, {5, 0}}]]
Out[4]=
In[5]:=
Graphics@
 ResourceFunction["WiggleLine"][
  ListInterpolation[Table[.1 Sin[10 x], {x, 0, 1, .1}], {{0, 1}}]]
Out[5]=

Options (7) 

Frequency (1) 

Change the wiggle frequency:

In[6]:=
Table[Graphics[{ResourceFunction["WiggleLine"][{{0, 0}, {1, 1}, {2, 0}},
     "Frequency" -> f]}], {f, 5}]
Out[6]=

Amplitude (1) 

Change the wiggle amplitude:

In[7]:=
Table[Graphics[{ResourceFunction["WiggleLine"][{{0, 0}, {1, 1}, {2, 0}},
     "Amplitude" -> a]}], {a, .1, .5, .1}]
Out[7]=

TaperFraction (2) 

Change the amount of taper at endpoints:

In[8]:=
Graphics[{ResourceFunction["WiggleLine"][{{0, 0}, {1, 1}, {2, 0}}, "TaperFraction" -> 1]}]
Out[8]=

No taper may produce a wiggle that misses its specified endpoints:

In[9]:=
Graphics[{ResourceFunction["WiggleLine"][{{0, 0}, {1, 1}, {2, 0}}, "TaperFraction" -> 0], Line[{{0, 0}, {1, 1}, {2, 0}}]}]
Out[9]=

Shape (2) 

There are number of built-in wiggly shapes:

In[10]:=
With[{pts = {{0, 0}, {1, 1}, {2, 0}}},
 GraphicsGrid@
  Partition[
   Graphics[{ResourceFunction["WiggleLine"][pts, "Shape" -> #]}, PlotLabel -> #] & /@ {"Sine", "Square", "Triangle", "Sawtooth", "Helix", "Semicircles", "Braid"}, UpTo[3]]
 ]
Out[10]=

Use custom function as a shape:

In[11]:=
Graphics[{ResourceFunction["WiggleLine"][{{0, 0}, {1, 1}, {2, 0}}, "Shape" -> Function[TriangleWave[#] - SquareWave[#]]]}]
Out[11]=

Points (1) 

Provide the exact number of line points to return:

In[12]:=
Length@First@
  ResourceFunction["WiggleLine"][{{0, 0}, {1, 0}}, "Points" -> 30]
Out[12]=

Applications (1) 

Draw a Feynman Diagram:

In[13]:=
Graphics[{
  Arrowheads[{{Medium, .5}}], Arrow[{{0, 1}, {1, 0}}], Arrow[{{1, 0}, {0, -1}}],
  Arrow[{{2, .2}, {3, 1}}], Arrow[{{3, -1}, {2, .2}}],
  Arrowheads[{{Small, .556, Graphics[Line[{{{-1, 1/2}, {0, 0}, {-1, -1/2}}}]]}}],
  Arrow@ResourceFunction["WiggleLine"][{{1, 0}, {2, .2}}, "Shape" -> "Helix", "Amplitude" -> .03]
  }]
Out[13]=

Possible Issues (1) 

If length of the line is too small, WiggleLine returns a single Point:

In[14]:=
ResourceFunction["WiggleLine"][{{0, 0}, {1*^-13, 0}}]
Out[14]=

Neat Examples (1) 

Wiggle some fractal curves:

In[15]:=
Graphics@
 ResourceFunction["WiggleLine"][HilbertCurve[4], "Frequency" -> 4, "Amplitude" -> 0.15, "Points" -> 20000, "TaperFraction" -> 0]
Out[15]=
In[16]:=
Graphics@
 ResourceFunction["WiggleLine"][SierpinskiCurve[4], "Frequency" -> .03, "Amplitude" -> 20, "Points" -> 30000, "TaperFraction" -> 0]
Out[16]=
In[17]:=
Graphics@
 ResourceFunction["WiggleLine"][PeanoCurve[3], "Frequency" -> 2, "Amplitude" -> .2, "Points" -> 10000, "TaperFraction" -> 0]
Out[17]=
In[18]:=
Graphics@
 ResourceFunction["WiggleLine"][KochCurve[3], "Shape" -> "Helix", "Frequency" -> 40, "Amplitude" -> .01, "Points" -> 10000, "TaperFraction" -> 0]
Out[18]=
In[19]:=
Graphics@
 ResourceFunction["WiggleLine"][ResourceFunction["LevyCCurve"][8], "Shape" -> "Helix", "Frequency" -> 10, "Amplitude" -> .02, "Points" -> 10000, "TaperFraction" -> 0]
Out[19]=

Requirements

Wolfram Language 14.0 (January 2024) or above

Version History

  • 1.0.0 – 04 April 2025

Related Resources

License Information