Function Repository Resource:

ApproximatedCurve

Source Notebook

Get an approximation to a parametric curve

Contributed by: Wolfram Staff (original content by Alfred Gray)

ResourceFunction["ApproximatedCurve"][c,{t,t0,tf,n}]

computes a line of n points approximating the parametric curve c with t from t0 to tf.

ResourceFunction["ApproximatedCurve"][c,{t,t0,tf,n},"type"]

gives a result based on "type".

Details and Options

Possible values of "type" are: "Coordinates", "Point", "Line", "PointLine", "Arrow", "Polygon", "BezierCurve", "BSplineCurve", "Tube", "BSplineCurveTube", "Region" or "DiscretizeRegion".

Examples

Basic Examples (5) 

Approximate cycles around a figure-eight curve:

In[1]:=
N@ResourceFunction[
  "ApproximatedCurve"][{Sin[t], Sin[t] Cos[t]}, {t, 0, 20, 20}, "Coordinates"]
Out[1]=

Approximate the curve with lines:

In[2]:=
ResourceFunction[
 "ApproximatedCurve"][{Sin[t], Sin[t] Cos[t]}, {t, 0, 20, 20}, "Line"]
Out[2]=

Show the lines:

In[3]:=
Graphics[
 ResourceFunction[
  "ApproximatedCurve"][{Sin[t], Sin[t] Cos[t]}, {t, 0, 20, 20}, "Line"]]
Out[3]=

Follow a path with arrows:

In[4]:=
Graphics[
 ResourceFunction[
  "ApproximatedCurve"][{Sin[t], Sin[t] Cos[t]}, {t, 0, 2 \[Pi], 30}, "Arrow"]]
Out[4]=

Define a curve in three dimensions:

In[5]:=
helix = Entity["SpaceCurve", "Helix"]["ParametricEquations"][1, 1][t]
Out[5]=

Polygonal approximation to a curve:

In[6]:=
Show[ParametricPlot3D[helix, {t, 0, 10}], Graphics3D[
  ResourceFunction["ApproximatedCurve"][helix, {t, 0, 10, 10}, "Line"]]]
Out[6]=

Different approximation to a curve:

In[7]:=
Graphics3D[
   ResourceFunction["ApproximatedCurve"][
    helix, {t, 0, 10, 20}, #]] & /@ {"Point", "PointLine", "Tube", "BezierCurve", "BSplineCurve", "BSplineCurveTube"}
Out[7]=

Convert points in the following closed curve into a tube. It requires less file space than a full parametrization plot:

In[8]:=
x[t_] := Cos[3 t]
y[t_] := Cos[4 t + Sqrt[2]]
z[t_] := Cos[5 t + Sqrt[3]]
In[9]:=
Graphics3D[
 Tube[ResourceFunction[
   "ApproximatedCurve"][{x[t], y[t], z[t]}, {t, 0, 10, 15}, BSplineCurve[#, SplineClosed -> True] &], .025]]
Out[9]=

Applications (6) 

Get a curve similar to a handwritten curve:

In[10]:=
Graphics[
 ResourceFunction[
  "ApproximatedCurve"][{Sin[t], Sin[t] Cos[t]}, {t, 0, 20, 17}, "BSplineCurve"]]
Out[10]=

Using AnglePath gives a different curve:

In[11]:=
Graphics[
 BSplineCurve[
  AnglePath[
   ResourceFunction[
    "ApproximatedCurve"][{Sin[t], Sin[t] Cos[t]}, {t, 0, 10, 200}, Identity]]]]
Out[11]=

Define an epicycloid:

In[12]:=
ec = Entity["PlaneCurve", "Epicycloid"]["ParametricEquations"][5, 3][
  t]
Out[12]=

Modify it using Accumulate:

In[13]:=
GraphicsRow[{ParametricPlot[Evaluate[ec], {t, 0, 7 \[Pi]}], Graphics[
   Line[Accumulate[
     N[ResourceFunction["ApproximatedCurve"][ec, {t, 0, 8 \[Pi], 200},
        "Coordinates"]]]]]}]
Out[13]=

Make a spline from the points of a curve:

In[14]:=
Graphics[
 FilledCurve@
  ResourceFunction[
   "ApproximatedCurve"][{Sin[t], Sin[t] Cos[t]}, {t, 0, 20, 10}, BSplineCurve[#, SplineClosed -> True] &]]
Out[14]=

Make a design from an epicycloid:

In[15]:=
ec = Entity["PlaneCurve", "Epicycloid"]["ParametricEquations"][1, 2][
  t]
Out[15]=
In[16]:=
Show[Graphics[{ResourceFunction["ApproximatedCurve"][
    ec, {t, 0, 4 Pi, 20}, "Polygon"]}], ParametricPlot[Evaluate[ec], {t, 0, 4 \[Pi]}]]
Out[16]=

Define an epicycloid:

In[17]:=
ec = Entity["PlaneCurve", "Epicycloid"]["ParametricEquations"][1, 2][
  t]
Out[17]=

Get a region:

In[18]:=
ResourceFunction[
 "ApproximatedCurve"][ec, {t, 0, 4 \[Pi], 20}, "Region"]
Out[18]=

Test if it is a region:

In[19]:=
RegionQ[ResourceFunction["ApproximatedCurve"][ec, {t, 0, 4 \[Pi], 20},
   "Region"]]
Out[19]=

Discretize the region:

In[20]:=
ResourceFunction[
 "ApproximatedCurve"][ec, {t, 0, 4 \[Pi], 20}, "DiscretizeRegion"]
Out[20]=

Compute some properties:

In[21]:=
{Area[%], Perimeter[%]}
Out[21]=

Create and visualize a nephroid:

In[22]:=
Graphics[
 Table[Scale[{ColorData["DarkBands"][.025 n], ResourceFunction["ApproximatedCurve"][
     Entity["PlaneCurve", "Nephroid"]["ParametricEquations"][1][
      t], {t, 0, 2 \[Pi], 12}, "FilledCurve"]}, Log[n]^(-1/2)], {n, 2,
    32}]]
Out[22]=

Properties and Relations (5) 

A crude approximation to arc length:

In[23]:=
Plus @@ ResourceFunction[
   "ApproximatedCurve"][{Sin[t], Sin[t] Cos[t]}, {t, 0, 2 \[Pi], 60}, EuclideanDistance @@@ Partition[N@#, 2, 1] &] // Timing
Out[23]=
In[24]:=
ArcLength[{Sin[t], Sin[t] Cos[t]}, {t, 0., 2. \[Pi]}] // Timing
Out[24]=

Successive approximation to arc length versus the number of steps:

In[25]:=
ListPlot[
 Table[Plus @@ ResourceFunction[
    "ApproximatedCurve"][{Sin[t], Sin[t] Cos[t]}, {t, 0, 2 \[Pi], n}, EuclideanDistance @@@ Partition[N@#, 2, 1] &], {n, 2, 20}]]
Out[25]=

Forced undersampling with MaxRecursion and PlotPoints:

In[26]:=
ParametricPlot[{Sin[t], Sin[t] Cos[t]}, {t, 0, 2 \[Pi]}, MaxRecursion -> 0, PlotPoints -> 15]
Out[26]=

Create a similar result using ApproximatedCurve:

In[27]:=
Graphics@
 ResourceFunction[
  "ApproximatedCurve"][{Sin[t], Sin[t] Cos[t]}, {t, 0, 2 \[Pi], 15}, "Line"]
Out[27]=

A polygon gives a similar result to FilledCurve:

In[28]:=
Graphics[
 ResourceFunction[
  "ApproximatedCurve"][{Sin[4 t], Sin[5 t]}, {t, 0, 2 \[Pi], 150}, "Polygon"]]
Out[28]=

Generalize CirclePoints:

In[29]:=
ellipse[a_, b_, t_] := {a Cos[t], b Sin[t]}
In[30]:=
Show[Graphics[
  ResourceFunction["ApproximatedCurve"][
   ellipse[2, 1, t], {t, 0, 2 \[Pi], 10}, "Line"]], ParametricPlot[Evaluate[ellipse[2, 1, t]], {t, 0, 2 \[Pi]}]]
Out[30]=

Distances between successive points are different:

In[31]:=
EuclideanDistance @@@ Partition[
  ResourceFunction["ApproximatedCurve"][
    ellipse[2, 1, t], {t, 0, 2 \[Pi], 10}, "Coordinates"] // N, 2, 1]
Out[31]=

Show the curve using points:

In[32]:=
Graphics[
 Table[{PointSize[.05 n], Hue[1/n], ResourceFunction["ApproximatedCurve"][
    ellipse[2, 1, t], {t, 0, 2 \[Pi], 20}, "Point"]}, {n, 5, 1, -1}]]
Out[32]=

Approximate a nephroid:

In[33]:=
nephroid = Entity["PlaneCurve", "Nephroid"]["ParametricEquations"][1][t]
Out[33]=
In[34]:=
Show[Graphics@
  ResourceFunction["ApproximatedCurve"][nephroid, {t, 0, 2 \[Pi], 10},
    "Line"], ParametricPlot[Evaluate[nephroid], {t, 0, 2 \[Pi]}]]
Out[34]=

Publisher

Enrique Zeleny

Version History

  • 1.0.0 – 24 April 2020

Source Metadata

Related Resources

License Information