Animation of an Inch Worm

Introduction

            An inch worm, while periodic and seemingly easy to animate, has fairly complex motion which switches from the rear to the front periodically.  This document will explain how I was able to provide a good deal of that complex motion with fairly minimal programming effort.

 

Methods

            The most important methods used were to make the parts of the inch worm modular as was explained in the document for the Human.  The starting element is the Foot.  This is just an ellipse that can rotate sinusoidally about an axis near its top. The Foot is attached to a larger ellipse called a Segment.  The Segment is also able to rotate about sinusoidally its center and this provides an interesting motion called undulation. 

The entire worm is a UserControl named wormUC.  wormUC has a List of these Segments and is also responsible for making single steps of the complex motions needed.

The module that requests the single steps is called InchWorm.   InchWorm has a Timer that first calls for the rear Segments to move while the center Segments Arch.  After the Arch is complete, the Timer calls for the front Segments to move while also removing the Arch.  All this is done with some fairly easy trigonometry expressed in wormUC. 

            The above methods take care of having the InchWorm move horizontally.  But I have also included ways for the InchWorm to climb a hill after traveling a given distance on the flat.  The transition from flat to hill is made difficult because the segments in the arch are not at the same height as the rear and front segments.  It is possible to obtain the height of all the segments by using the Canvas.GetTop() method.  If, for each step, one actually uses the differential of the arched segment height change, and adds that to the height as well as the height change due to the slope, then the segments in the arch are well behaved during both the transition from flat to slope as well as on the flat and slope.