Morphing Surfaces

Concept

In our contemporary multimedia culture, students are well familiar with three dimensional images being changed from one form to another (frequently called "morphing").  This Mathematica notebook demonstrates how this morphing process can be accomplished using principles of the mathematical concept of a surface homotopy.  It goes on to suggests ways in which this instructors can use this theme to help multivariable calculus students explore 3D surfaces and the corresponding functions in a way that stimulates the students' curiosity and creativity.
Development of this notebook and suggested usage came from a talk given by Alan Horwitz entitled, "Drawing and Destroying Surreal-Life Objects with Mathematica" given at the 12th International Conference on Technology in Collegiate Mathematics in San Franscisco, CA during Nov 1999.  Further information on surface homotopy can be found in: "Topology: A First Course", by James R. Munkres.
This notebook was developed by Lt Col Steve Hadfield, PhD, at the United States Air Force Academy, Department of Mathematical Sciences.

Definitions

A "homotopy" is a mapping of one mathematical expression (and its geometric realization) into another expression.  One realization of a homotopy consists of an initial function (we use z=f(x,y)) and a final function (z=g(x,y)) together with disipation (u(t)) and emergence (v(t)) functions that are combined into one composite mapping.  For our purposes we'll restrict the functions f(x,y) and g(x,y) to be defined over a common domain and relax the boundary conditions that are normally required for a homotopy.  The disipation function, u(t), must satisfy u(0)=1 and u(1)=0; while the emergence function, v(t), must satisfy v(0)=0 and v(1)=1.  The four component functions are combined as follows into the surface homotopy where the deformation parameter, t, is used to progress from the initial function (surface) to the final one:
	h(x,y,t) = u(t)*f(x,y) + v(t)*g(x,y)	for 0 <= t <= 1.
This method of combination insures that h(x,y,0) = f(x,y) and h(x,y,1) = g(x,y) which produces the desired effect.

Suggested Pedagogical Usages

A critical skill for the multivariable calculus student is the ability to visualize and understand the 3D surface plots for functions of the form z = f(x,y).  After a simple explanation and demonstration of the concept of a homotopy, the students can easily vary both the initial and final surface functions to produce interesting and informative morphing animations.  Instructors could have the students use a specific set of initial and final functions which would get the students familiar with the functions that might be used extensively later in the course.
They could also just provide surface plots and have the students come up with corresponding functions to help the students develop an understanding of the relationship between the function's algebraic definition and its surface plot.
After either of these first exercises, the students could be turned loose to create their own functions and animations perhaps with rewards for the most creative.
Another possibility would be to have the students experiment with different u(t) and v(t) functions that control the morphing process.
Another potential use of this theme would be to have the students experiment with various optional parameters that are provided on the Plot3D command in Mathematica.  Some of the possible parameters to experiment with are shown in the examples below.

Examples

Example 1:  A simple first illustration of using homotopy to produce a morphing animation.  Comments in the code describe what each item is and a simple linear set of transition functions are used.  The resulting animation can be run by just double-clicking inside of the surface plot.

Clear[f, g, h, u, v, x, y, n, t]    

f[x_, y_] = 
        (x^2) - (y^2);                       
g[x_, y_] = -(x^2) + 
          (y^2);                    
u[t_] = 1 - t;                    
v[t_] = t;                          
n = 
        20;                               (* 
      Number of steps to use *) 

 (* The full mapping function *) 
h[x_, y_, t_] = 
        u[t]*f[x, y] + 
          v[t]*g[x, y];

  
Table[
      Plot3D[h[x, y, i/n], {x, -2, 2}, {y, -2, 2}, 
        AxesLabel -> {"x", "y", "z"}, AspectRatio -> 1, 
        PlotPoints -> 25, Mesh -> False, 
        PlotRange -> {-4, 4}], {i, 0, n}]

Example 2:  This example shows how the initial code was copied, pasted, and modified to produce a more interesting animation.  The transition functions u(t) and v(t) were not modified.

Clear[f, g, h, u, v, x, y, n, t]    

f[x_, y_] = 2  Sin[2 ((x^2) + (y^2))];        
g[x_, y_] = -(x^2) + 
          (y^2);                    
u[t_] = 1 - t;                    
v[t_] = t;                          
n = 
        20;                               (* 
      Number of steps to use *) 

 (* The full mapping function *) 
h[x_, y_, t_] = 
        u[t]*f[x, y] + 
          v[t]*g[x, y];

  
Table[
      Plot3D[h[x, y, i/n], {x, -2, 2}, {y, -2, 2}, 
        AxesLabel -> {"x", "y", "z"}, AspectRatio -> 1, 
        PlotPoints -> 40, Mesh -> False, 
        PlotRange -> {-4, 4}], {i, 0, n}]

Example 3:  This example illustrates how the transition functions can be modified to produce more interesting morphing behavior.  Having the students describe what is happening with these transition functions could be a useful exercise.

Clear[f, g, h, u, v, x, y, n, t]    

f[x_, y_] = 2  Sin[2 ((x^2) + (y^2))];        
g[x_, y_] = -(x^2) + 
          (y^2);                    
u[t_] = 1 - t;                    
v[t_] = 
        Sin[(5  Pi*t)/
            2];                          
n = 
        20;                               (* 
      Number of steps to use *) 

 (* The full mapping function *) 
h[x_, y_, t_] = 
        u[t]*f[x, y] + 
          v[t]*g[x, y];

  
Table[
      Plot3D[h[x, y, i/n], {x, -2, 2}, {y, -2, 2}, 
        AxesLabel -> {"x", "y", "z"}, AspectRatio -> 1, 
        PlotPoints -> 40, Mesh -> False, 
        PlotRange -> {-4, 4}], {i, 0, n}]

Example 4:  This example shows how you can use a set of (x, y, z) points to define either the initial and/or final surface by using these points to built an interpolating function that is then used in the mapping that does the morphing.

Clear[f, g, h, u, v, x, y, n, t, rawpoints]   (* 
      Clear symbols used *) 

 (* 
      Initial surface is a set of regularily spaced (x, 
          y) points with randomly generated values for z *) 

rawPoints = 
        Flatten[Table[{-2 + i/4, -2 + j/4, 
              Random[Real, {-4, 4}]}, {i, 0, 16}, {j, 0, 16}], 
          1];

 (* 
      Instead of randomly generated function values,  
      you could import a list of (x, y, 
          z) points that define any surface that you wish .   The required format is {{x1, y1, z1},  {x2,  y2,  
            z2},   ...  ,  {xn,  yn,  
            zn}} and the Mathematica Import command can easily accept various data formats into this type of structure.  *) 

 (* 
      This next command builds and interpolating function f (x, 
          y) from the raw points and uses this as the initial surface function *) 
f = 
        Interpolation[
          rawPoints];

g[x_, y_] = -(x^2) + 
          (y^2);                    
u[t_] = 1 - t;                    
v[t_] = t;                          
n = 
        20;                               (* 
      Number of steps to use *) 

 (* The full mapping function *) 
h[x_, y_, t_] = 
        u[t]*f[x, y] + 
          v[t]*g[x, y];

  
Table[
      Plot3D[h[x, y, i/n], {x, -2, 2}, {y, -2, 2}, 
        AxesLabel -> {"x", "y", "z"}, AspectRatio -> 1, 
        PlotPoints -> 25, Mesh -> False, 
        PlotRange -> {-4, 4}], {i, 0, n}]