On this page:
7.8.1 Interpolation without Guidelines
7.8.2 Interpolation with Guidelines
7.8.3 Exercises 40
7.8.3.1 Question 157

7.8 Interpolations

Cross section interpolation, also known as shape morphing, allows the creation of a three-dimensional object through the interpolation of planar sections. In Khepri, this interpolation is implemented by the loft and the loft_ruled functions. These functions operate from an ordered array of planar sections (that might be curves or regions), which can be optionally complemented with guidelines to minimize possible mistakes in the interpolation process. The use of guidelines is particularly important in the case of planar sections with rectilinear parts.

In the next sections, we will analyze separately each of these forms of interpolation.

7.8.1 Interpolation without Guidelines

There are two fundamental ways of doing shape interpolation without guidelines: by generating a ruled surface (i.e., surfaces generated by a movement of a line segment) between each planar section, or by generating a smooth surface (i.e., without sudden slope shifts) that comes closer to several planar sections. The interpolation by ruled surfaces is implemented by the loft_ruled function, while the interpolation by smooth surfaces is done with the loft function.

To compare the effects of these two functions, consider the following expression that creates a ruled surface interpolation from three circles, represented on the left of this figure:

let circ0 = surface_circle(xyz(0, 0, 0), 4),

    circ1 = surface_circle(xyz(0, 0, 2), 2),

    circ2 = surface_circle(xyz(0, 0, 4), 3)

  loft_ruled([circ0, circ1, circ2])

end

In the same this figure, on the right, we can find a smooth surface interpolation of the same three circles, generated by the following expressions:

let circ0 = surface_circle(xyz(0, 9, 0), 4),

    circ1 = surface_circle(xyz(0, 9, 2), 2),

    circ2 = surface_circle(xyz(0, 9, 4), 3)

  loft([circ0, circ1, circ2])

end

Surface interpolation of three circles: on the left, with a ruled surface interpolation, and on the right, with a smooth surface interpolation.

image

7.8.2 Interpolation with Guidelines

It is relatively obvious that there is an unlimited number of different surfaces that interpolate two given sections. Unfortunately, not all of them match the desired outcome, especially when it is necessary to produce an interpolation between two very different sections.

This behavior can be seen in this figure, which presents two interpolations between a hexagon and a triangle and where the lack of uniformity is clearly visible. Different interpolations are produced depending not only on the CAD application that is being used but also on the version of that application. The interpolation on the left was generated by the following expression:

loft(

  [surface_regular_polygon(

     6, xyz(0, 0, 0), 1.0, 0),

   surface_regular_polygon(

     3, xyz(0, 0, 5), 0.5, pi/6)])

Note that, on the left side of this figure, one of the sides of the triangle is directly mapped into one of the sides of the hexagon, thus forcing the interpolation to distort the remaining two sides of the triangle to map the remaining five sides of the hexagon.

Fortunately, the loft function offers other ways of doing interpolation that minimize the possibility of errors. This function receives not only the array of sections to interpolate, but also an array of curves that guide the interpolation process. Using this function, we can reproduce the interpolation on the right of this figure by establishing guidelines between the relevant vertices of each polygon. These guidelines will force Khepri to generate an interpolation that integrates these lines on the generated surface, and thus controlling the pairing of points between the sections to interpolate. To that end, we will generate three vertices of the hexagon that, together with the three vertices of the triangle, allow the creation of the guidelines.

Since we need to build the guidelines from the polygons’ vertices, we will start by defining a function that, with two arrays of points, creates an array of lines that use one point of each array at a time:

guides(p0s, p1s) =

  if p0s == []

    []

  else

    [line(p0s[1], p1s[1]),

     guides(p0s[2:end],

            p1s[2:end])...]

  end

Next, we generate three non-consecutive vertices of the hexagon that, together with those of the triangle, allow the creation of the guidelines:

loft(

  [surface_regular_polygon(

     6, xyz(3, 0, 0), 1.0, 0),

   surface_regular_polygon(

     3, xyz(3, 0, 5), 0.5, pi/6)],

  guides(

    regular_polygon_vertices(

      3, xyz(3, 0, 0), 1.0, 0),

    regular_polygon_vertices(

      3, xyz(3, 0, 5), 0.5, pi/6)))

The evaluation of the previous expression allows Khepri to produce a more uniform interpolation between the hexagon and the triangle, as can be seen on the right side of this figure.

Top view of an interpolation between a hexagonal section and a triangular section. On the left, the interpolation was performed without guidelines. On the right, the interpolation was performed with guidelines, associating three non-consecutive of the hexagon to the three vertices of the triangle.

image

7.8.3 Exercises 40
7.8.3.1 Question 157

Consider the interpolation between two random closed curves positioned on different heights, as presented in the following figure:

image

Each curve is a spline produced with points generated by the random_circle_points function defined in the exercise of Question 104. Write an expression capable of generating a solid similar to the ones presented in the previous image.