10.1 Computation of Parametric Functions

Since the parametric representation significantly simplifies the creation of curves, we now intend to define functions that, from the parametric description of a curve, produce an array of points that belong to that curve. To generate these points we will specify the limits of the interval of the parameter \(t\) and the progressive increment of its value \(\Delta_t\), producing \(t_0, t_0+\Delta_t, t_0+2\Delta_t,\ldots,t_1\). For example, to generate \(n\) uniformly spaced points that form a circle of radius \(r\) we need to consider the interval \([0,2\pi[\) and a angular separation of \(\Delta_t=\frac{2\pi}{n}\). Note that the interval is open at \(t=2\pi\) because the corresponding point coincides with the one at \(t=0\).

To generate values of \(t\) uniformly spaced by \(\Delta_t\) we can use the function enumerate, defined in section Enumerations, which serves precisely this purpose, so that we can map the parametric function:

map(t -> pol(r, t), enumerate(0, 2*pi, dt))

As usual, we can encapsulate the previous expression with a parametrized function, which we will generalize to allow the specification of the circle center "p":

circle_points(p, r, dt) =

  map(t -> p + vpol(r, t), enumerate(0, 2*pi, dt))

Figref{fig:pontosCirc} illustrates the points generated by the circle_points function for different \(\Delta_t\) values.

Points along a circle. From left to right, \(\Delta_t=\frac{2\pi}{10}\), \(\Delta_t=\frac{2\pi}{20}\), \(\Delta_t=\frac{2\pi}{30}\), e \(\Delta_t=\frac{2\pi}{40}\).

image

To see a more practical example, let us consider the Archimedean spiral: a curve described by a point which moves with constant velocity \(v\) along a radius that rotates around a center point with constant angular velocity \(\omega\). In polar coordinates, the equation of the Archimedean spiral has the form

\[\rho=\frac{v}{\omega}\phi\]

or, with \(\alpha=\frac{v}{\omega}\),

\[\rho=\alpha\phi\]

which, as can be seen, is a parametric description in terms of \(\phi\).

To convert the polar representation of the Archimedean spiral to the parametric form, we only have to replace \(\phi\) with \(t\) and add an equation in terms of \(\phi\), that is

\[\left\{ \begin{aligned} \rho(t)&=\alpha t\\ \phi(t)&= t \end{aligned}\right.\]

The computation of the coordinates of the Archimedean spiral can now be accomplished by mapping the parametric equation onto the array of values of \(t\):

archimedean_spiral(alpha, t0, t1, dt) =

  map(t -> pol(alpha*t, t),

      enumerate(t0, t1, dt))

In the previous definition, the Archimedean spiral is positioned at the origin. If we want to make the center of a spiral a parameter \(p\), we only need to operate a simple translation, i.e.:

archimedean_spiral(p, alpha, t0, t1, dt) =

  map(t -> p+vpol(alpha*t, t),

      enumerate(t0, t1, dt))

This figure shows three Archimedean spirals drawn from the following invocations:

> spline(archimedean_spiral(xy(0, 0), 2.0, 0, 4*pi, 0.1))

Spline(...)

> spline(archimedean_spiral(xy(50, 0), 1.0, 0, 6*pi, 0.1))

Spline(...)

> spline(archimedean_spiral(xy(100, 0), 0.2, 0, 36*pi, 0.1))

Spline(...)

Archimedean spirals. From left to right, the parameters are \(\alpha=2, t \in [0,4\pi]\), \(\alpha=1, t \in [0,6\pi]\), and \(\alpha=0.2, t \in [0,36\pi]\).

image