Function Repository Resource:

ParameterizePolygon

Source Notebook

Find the parameterization of a curve that linearly connects a list of points

Contributed by: Garrett Dubofsky, Wolfram|Alpha Math Team

ResourceFunction["ParameterizePolygon"][{p1,p2,},t]

parameterizes the polygon defined by points pi with variable t from 0 to 1.

ResourceFunction["ParameterizePolygon"][{{p11,p12,},{p21,},},t]

parameterizes the curve defined by a collection of polygons.

ResourceFunction["ParameterizePolygon"][{p1,p2,},{t,tmin,tmax}]

creates a parameterization with variable t from tmin to tmax.

ResourceFunction["ParameterizePolygon"][{p1,p2,},{t0,tmin,tmax}]

evaluates the parameterization with domain tmin to tmax at t0.

Details

The collection of points pi can be in any dimension.
Points pi can be a combination of symbolic and numeric values.
The parameterization evaluates to {} for any inputs outside the domain.
The speed of the parameterization is consistent; the Euclidean distance between pairs of points is proportional to the domain allocated to the line connecting the points.
The following options are supported:
"ClosedCurve"Truewhether to connect the first and last points
"ExactValues"Truethe precision of the output
"Orientation"Automaticthe order used to evaluate the list of points

Examples

Basic Examples (2) 

Parameterize the line from {0,1} to {1,1} over the domain[0,1]:

In[1]:=
ResourceFunction["ParameterizePolygon"][{{0, 1}, {1, 1}}, t]
Out[1]=

Parameterize the 3D polygon formed by three points:

In[2]:=
ResourceFunction[
 "ParameterizePolygon"][{{0, 0, 0}, {1, 1, 0}, {1, 2, 1}}, t]
Out[2]=

Parameterize the same polygon over the domain[-3,3]:

In[3]:=
ResourceFunction[
 "ParameterizePolygon"][{{0, 0, 0}, {1, 1, 0}, {1, 2, 1}}, {t, -3, 3}]
Out[3]=

Evaluate the above parameterization at t=-1/2:

In[4]:=
ResourceFunction[
 "ParameterizePolygon"][{{0, 0, 0}, {1, 1, 0}, {1, 2, 1}}, {-1/2, -3, 3}]
Out[4]=

Scope (6) 

Parameterize a collection of polygons:

In[5]:=
ResourceFunction[
 "ParameterizePolygon"][{{{0, 0}, {0, 1}, {1, 0}}, {{-1, -1}, {-1, 0}}}, t]
Out[5]=

Find the linear parameterization between a combination of numeric and symbolic points:

In[6]:=
ResourceFunction["ParameterizePolygon"][{{x, 0}, {1, y}, {1, 0}}, t]
Out[6]=

Parameterize a 1D curve:

In[7]:=
ResourceFunction["ParameterizePolygon"][{{8}, {2}, {-4}, {12}}, t]
Out[7]=

Parameterize curves in 4 dimensions or greater:

In[8]:=
ResourceFunction[
 "ParameterizePolygon"][{{0, 0, 0, 0}, {0, -1, 1, 0}, {1, 0, 1, 0}, {1, 0, 0, 0}}, t]
Out[8]=

The list of points can be substituted with Rectangle instead:

In[9]:=
ResourceFunction["ParameterizePolygon"][Rectangle[], t]
Out[9]=

Substituting with Triangle is also supported:

In[10]:=
ResourceFunction["ParameterizePolygon"][Triangle[], t]
Out[10]=

Besides Triangle[], the heads Line, Triangle, and Polygon are ignored:

In[11]:=
ResourceFunction["ParameterizePolygon"][#[{{1/2, 0}, {1, 0}, {0, 0}}],
    t] & /@ {Line, Triangle, Polygon}
Out[11]=

The resulting piecewise function can be input into ParametricPlot or ParametricPlot3D:

In[12]:=
ParametricPlot[
 ResourceFunction[
  "ParameterizePolygon"][{{3/2, 0}, {-2, 4}, {\[Pi], 3}, {-2, 1}, {1, 5}}, t], {t, 0, 1}]
Out[12]=
In[13]:=
ParametricPlot3D[
 ResourceFunction[
  "ParameterizePolygon"][{{0, 0, 0}, {0, 0, 1}, {1, 0, 1}, {0, 1, 0}, {1, 1, 0}, {0, 1, 1}}, t], {t, 0, 1}]
Out[13]=

Pairs of adjacent points that are the same are treated as a single point:

In[14]:=
SameQ[ResourceFunction[
  "ParameterizePolygon"][{{0, 0}, {0, 0}, {0, 0}, {1, 1}, {1, 1}}, t],
  ResourceFunction["ParameterizePolygon"][{{0, 0}, {1, 1}}, t]]
Out[14]=

Options (3) 

Determine if the list of points defines a closed curve:

In[15]:=
ParametricPlot[
   ResourceFunction["ParameterizePolygon"][{{0, 0}, {1, 0}, {1, 1}}, t, "ClosedCurve" -> #], {t, 0, 1}] & /@ {True, False}
Out[15]=

Each polygon within a collection is automatically closed:

In[16]:=
ParametricPlot[
 ResourceFunction[
  "ParameterizePolygon"][{{{0, 0}, {1, 0}, {1, 1}}, {{-1/2, 1/2}, {0, 1/2}, {0, 1}}}, t], {t, 0, 1}]
Out[16]=

Setting "ExactValues" to False causes the output to be imprecise:

In[17]:=
ResourceFunction[
 "ParameterizePolygon"][{{-5, 3}, {-2, 1}, {4, -1}}, t, "ExactValues" -> False]
Out[17]=

Determine the order of which the points are transversed using the "Orientation" option:

In[18]:=
Table[ParametricPlot[
  ResourceFunction["ParameterizePolygon"][{{-1, -1}, {1, -1}, {0, 1}},
    t, "Orientation" -> "Forwards"], {t, 0, k}, PlotRange -> 1.1, ImageSize -> 150], {k, 1/5, 1, 1/5}]
Out[18]=
In[19]:=
Table[ParametricPlot[
  ResourceFunction["ParameterizePolygon"][{{-1, -1}, {1, -1}, {0, 1}},
    t, "Orientation" -> "Backwards"], {t, 0, k}, PlotRange -> 1.1, ImageSize -> 150], {k, 1/5, 1, 1/5}]
Out[19]=

Curves formed using Rectangle are transversed clockwise by default:

In[20]:=
Table[ParametricPlot[
  ResourceFunction["ParameterizePolygon"][Rectangle[{1, 1}, {-1, -1}],
    t], {t, 0, k}, PlotRange -> 1.1, ImageSize -> 150], {k, 1/5, 1, 1/5}]
Out[20]=

The curve formed from Triangle[] is transversed counterclockwise by default:

In[21]:=
Table[ParametricPlot[
  ResourceFunction["ParameterizePolygon"][Triangle[], t], {t, 0, k}, PlotRange -> {{-0.1, 1}, {-0.1, 1}}, ImageSize -> 150], {k, 1/5, 1, 1/5}]
Out[21]=

Applications (5) 

Use the parameterization to analyze a function with 2D domain along a given curve:

In[22]:=
testFun[{x_, y_}] := Sin[Cos[x] + Sin[y] + y + x];
In[23]:=
paraFun[t_] := ResourceFunction["ParameterizePolygon"][CirclePoints[3, 6], t, "ExactValues" -> False];

Flatten out the 3D curve to see its output along the parameterization:

In[24]:=
Plot[testFun[paraFun[t]], {t, 0, 1}]
Out[24]=

Superimpose the output along the parameterization atop the 3D function curve:

In[25]:=
p1 = Plot3D[testFun[{x, y}], {x, -5, 5}, {y, -5, 5}];
In[26]:=
p2 = ParametricPlot3D[
   Append[paraFun[t], testFun[paraFun[t]]], {t, 0, 1}, PlotStyle -> Thickness[0.01]];
In[27]:=
Show[p1, p2]
Out[27]=

Visualize the output of a function with three variables along a 3D polygon:

In[28]:=
testFun3D[{x_, y_, z_}] := Sin[Cos[x] + Sin[y] + Sinh[z] + y + x + z];
In[29]:=
paraFun3D[t_] := ResourceFunction[
   "ParameterizePolygon"][{{0, 0, 0}, {0, 0, 1}, {1, 0, 1}, {0, 1, 0}, {1, 1, 0}, {0, 1, 1}}, t, "ExactValues" -> False];

Plot the polygon with Hue shading corresponding to the value of the function:

In[30]:=
ParametricPlot3D[paraFun3D[t], {t, 0, 1}, ColorFunction -> Function[{x, y, z}, Hue[testFun3D[{x, y, z}]/2]], PlotStyle -> Thickness[0.01]]
Out[30]=

Plot the same function values as a timeline of the parameterization:

In[31]:=
Plot[testFun3D[paraFun3D[t]], {t, 0, 1}, PlotStyle -> Thickness[0.01],
  ColorFunction -> Function[{x, y}, Hue[testFun3D[paraFun3D[x]]/2]]]
Out[31]=

This process can be generalized to find the output of a 4 variable function along a 4D curve:

In[32]:=
testFun4D[{x_, y_, z_, w_}] := x^2 + y^3 + 2 Sin[z^2 - Cos[3 w^2]];
In[33]:=
paraFun4D[t_] := ResourceFunction[
   "ParameterizePolygon"][{{0, 0, 1, 0}, {0, 1, 0, 1}, {1, 0, 1, 0}, {0, 1, 1, 0}, {1, 1, 1, 0}, {1, 0, 1, 1}}, t, "ExactValues" -> False];
In[34]:=
Plot[testFun4D[paraFun4D[t]], {t, 0, 1}]
Out[34]=

Higher-dimensional polygons can be visualized using Norm along their parameterization:

In[35]:=
Plot[Norm[
  ResourceFunction[
   "ParameterizePolygon"][{{0, 0, 0, 0, 0}, {1, 2, 3, 4, 5}, {5, -1, 2, 5, -7}, {-1, -4, 1, 0, 3}}, t]], {t, 0, 1}]
Out[35]=

Linear functions can be generated using the plots of 1D polygons:

In[36]:=
Plot[ResourceFunction[
  "ParameterizePolygon"][{{1}, {-3}, {2}, {5}, {-7}}, t], {t, 0, 1}]
Out[36]=

Regular polygons can be parameterized:

In[37]:=
Table[ParametricPlot[
  ResourceFunction["ParameterizePolygon"][CirclePoints[k], t, "ExactValues" -> False], {t, 0, 1}, ImageSize -> 100, Ticks -> None], {k, 2, 8}]
Out[37]=

Other named curves can also be parameterized:

In[38]:=
ParametricPlot[
   ResourceFunction["ParameterizePolygon"][#, t, "ClosedCurve" -> False, "ExactValues" -> False], {t, 0, 1}] & /@ {PeanoCurve[2], HilbertCurve[3], SierpinskiCurve[2], KochCurve[2]}
Out[38]=

Properties and Relations (1) 

The resource function ColorWinding uses ParameterizePolygon internally and to generate the "PolygonPlot" output:

In[39]:=
ResourceFunction["ColorWinding"][{x, y}, {x, y}, {{1, 0}, {-2, 4}, {\[Pi], 3}, {-2, 1}, {1, 5}}, "PolygonPlot"]
Out[39]=

Possible Issues (4) 

Plotting functions are more efficient when the parameterization has inexact values:

In[40]:=
First[AbsoluteTiming[
  ParametricPlot3D[
   ResourceFunction[
    "ParameterizePolygon"][{{0, 0, 0}, {2, 3, 4}, {1, -1, 5}, {5, 9, -12}}, t], {t, 0, 1}]]]
Out[40]=
In[41]:=
First[AbsoluteTiming[
  ParametricPlot3D[
   ResourceFunction[
    "ParameterizePolygon"][{{0, 0, 0}, {2, 3, 4}, {1, -1, 5}, {5, 9, -12}}, t, "ExactValues" -> False], {t, 0, 1}]]]
Out[41]=

Some polygons encounter a precision error that can be resolved by setting "ExactValues" to False:

In[42]:=
ResourceFunction["ParameterizePolygon"][CirclePoints[5], t]
Out[42]=
In[43]:=
ResourceFunction["ParameterizePolygon"][CirclePoints[5], t, "ExactValues" -> False]
Out[43]=

Sometimes ParametricPlot will include a connecting line between multiple polygons:

In[44]:=
ParametricPlot[
 ResourceFunction[
  "ParameterizePolygon"][{{{0, 0}, {1, 0}, {1, 1}}, {{-1/2, 1/2}, {0, 1/2}, {0, 1}}}, t, "ExactValues" -> False], {t, 0, 1}]
Out[44]=

Increasing the number of PlotPoints will remove extraneous points along the curve:

In[45]:=
ParametricPlot3D[
   ResourceFunction["ParameterizePolygon"][SpherePoints[10], t, "ExactValues" -> False], {t, 0, 1}, ImageSize -> 300, PlotRange -> {{0.25, 1}, {0, .75}, {-.20, -0.5}}, PlotPoints -> #] & /@ {Automatic, {40, 40}}
Out[45]=

Neat Examples (3) 

Plot the parameterization of a cube:

In[46]:=
Table[ParametricPlot3D[
  ResourceFunction[
   "ParameterizePolygon"][{{0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {1, 1, 1}, {1, 1, 0}, {0, 1, 0}, {0, 1, 1}, {0, 0, 1}, {0, 0, 0}, {1, 0,
      0}, {1, 1, 0}, {1, 1, 1}, {0, 1, 1}, {0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {1, 0, 1}, {1, 0, 0}}, t, "ExactValues" -> False], {t, 0, tmax}, PlotPoints -> {300, 300}, ImageSize -> 125, Axes -> False, PlotRange -> {{0, 1}, {0, 1}, {0, 1}}], {tmax, 0.1, 0.9, 0.1}]
Out[46]=

Create abstract shapes using a single parameterization:

In[47]:=
ParametricPlot[#, {t, 0, 1}, PlotStyle -> Red] &[
 ResourceFunction["ParameterizePolygon"][
  Table[CirclePoints[k*{1, \[Pi]/64}, 3], {k, 1, 12}], t, "ExactValues" -> False]]
Out[47]=

Applying a function along a 2D parameterization adds a new dimension to the shape:

In[48]:=
testFun2[{x_, y_}] := Sin[2 x] + Cos[3 y]^3;
In[49]:=
paraFun2[t_] := ResourceFunction["ParameterizePolygon"][HilbertCurve[3], t, "ExactValues" -> False];
In[50]:=
paraFun3[t_] := ResourceFunction[
   "ParameterizePolygon"][{{1, 1}, {1, -1}, {-1, -1}, {-1, 3/4}, {3/4,
      3/4}, {3/4, -3/4}, {-3/4, -3/4}, {-3/4, 1/2}, {1/2, 1/2}, {1/2, -1/2}, {-1/2, -1/2}, {-1/2, 1/4}, {1/4, 1/4}, {1/4, -1/4}, {-1/4, -1/4}, {-1/4, 0}, {0, 0}}, t, "ClosedCurve" -> False, "ExactValues" -> False];
In[51]:=
ParametricPlot3D[
 Append[paraFun2[t], testFun2[paraFun2[t]]], {t, 0, 1}, PlotStyle -> Thickness[0.01], ColorFunction -> Function[{x, y, z}, Hue[z]], ViewPoint -> {0, 0, 10.}]
Out[51]=
In[52]:=
ParametricPlot3D[
 Append[paraFun3[t], testFun2[paraFun3[t]]], {t, 0, 1}, PlotStyle -> Thickness[0.01], ColorFunction -> Function[{x, y, z}, Hue[z]], ViewPoint -> {0, 0, 10.}]
Out[52]=

Publisher

Garrett Dubofsky

Version History

  • 1.0.0 – 29 August 2022

Related Resources

Author Notes

The Piecewise function defaults to {} so that ParametricPlot and ParametricPlot3D do not encounter an error when evaluating the function outside the specified domain.

As seen in ParameterizePolygon[{{1},{2},{3}},t], each 1D point is surrounded by brackets to distinguish them from a higher-dimension point such as {1,2,3}.

To view the full source code for ParameterizePolygon, evaluate the following:

License Information