netkingcol

thinking outside the tank

Crop Duster Animation

leave a comment »

In October 2016 I was contacted by Lem Shattuck, a professional agricultural aviator, who asked me if it would be possible to create an animation in Google Earth of the path followed by a crop-duster aeroplane using GPS data recorded in-flight. The animation would be used in evidence in a trial in which he had been recruited as an expert witness. I was confident that the answer was ‘yes’ but it took several months of exchanging information with Lem to get the results he needed.

The flight in question ended tragically when the plane struck the outer guy of a 1000-foot mast and the pilot lost his life. The details of the case will not be discussed here, rather I want to describe how some software I developed a few years ago, for my own leisure, was adapted to try to clarify what happened and to illustrate how, perhaps, the incident could have been avoided.

There were two principal areas to be addressed:

  1. Create the scene in Google Earth.
  2. Use the animation software to ‘fly’ the model through the scene.

Creating the Google Earth Scene

There were two masts at the site which we called the ‘west tower’ and the ‘east tower’. The plane crashed into the west tower. The 3D Warehouse provided the initial tower model; this had to be modified in SketchUp to make it more realistic. The following series of clickable images shows some of the ways we made the model look closer to what the agricultural pilot sees on a daily basis. Also, one version of the tower was to include high-visibility sleeves and marker balls (Tana markers) on its outer guys.

The modifications included:

  • The original model used rectangular strips to represent the guy wires (figure 1.) and only two of these at each anchor point. The flat guys were replaced with cylinders of the correct diameter, textured to look like weathered steel (figure 2). The number of guys was also increased to four at each anchor.
  • High-visibility sleeves were added by drawing and colouring concentric cylinders (figure 3).
  • Tana markers were added at suitable intervals (figure 4).
  • The anchor points had to be rotated and re-positioned so they coincided with their actual positions at the site (figure 5 and 6). The whole model was scaled and geo-located over multiple iterations to make it as accurate and representative as we could.

A couple of large trees bordered the field and suitable models were placed in the scene (figure 7).

8. M18 aircraft

Lem bought a 3D model of an M18 aircraft, a type commonly used by agricultural pilots and was the aircraft flown on this occasion. I made a few modifications to the model, such as adding the semi-transparent cylinder that simulates propeller rotation. For the animation, the model also had to be oriented so that it would be in straight and level flight and would fly on the heading set by the KML.

Animation software

At the time Lem contacted me I already had some software, written in C#, that was able to animate marine vessels and aeroplanes, as demonstrated by these videos:

Aircraft animations were created from KML input files which included all of the settings that define how an animation should look. One key feature in the specification is the Path, which includes a series of Placemarks, representing the points through which the plane should fly. Settings could be attached at various points in the input  to achive certain effects, such as: identify the model to animate; define the speed at which the model should ‘fly’; determine how much the plane should roll for a given change in heading.

I should point out that flight animations move two objects through Google Earth space. One is the model itself, and the other is the camera that follows the model on its journey.

My software, as it existed at the start of the project, would fit spline curves between the Placemarks in a Path for both the model and the camera (see this video for a demonstration, using javascript, of the cubic spline technique).

cubicSpline

Cubic Spline Demonstration

The cubic spline curve fitting creates multiple series of intermediate points that define the flight path of the model, and the location and orientation of the following camera.

Having generated these curves, all that remained would be to create the animation, step by step, by moving the model to successive points, modifying its heading, pitch, and roll at each point. Likewise, the following camera would be advanced to its next location and be rotated about its three axes to point at the model.

Software modifications for the crop duster animation

What Lem was asking me to do was to make an animation using about two-and-a-half minutes of GPS data from a system in common use by agricultural aviators which records a position every two seconds. These data-points were much closer together than I had previously used and would need some tweaking of the interpolation routines.

Another change was to provide two types of view, one to give the pilot’s point of view during the flight, and the other to view the flight from a fixed range and orientation.

Finally, the animations needed to be run using historical imagery which would show the position of the Sun at the time of the incident.

Results

The following links take you to the YouTube videos that acted as backups to the animations that Lem would present in court:

In these videos the LineStrings coloured in yellow represent the GPS data-points while the smoother, white lines, shows the results of the cubic spline interpolation. The red line shows an extrapolation of the GPS data from the last data-point recorded to the known location of the crash.

 

 

 

Advertisements

Bookbinding Project #63 – Birthday Card Recycling

leave a comment »

Some people excel when it comes to choosing greeting cards. My Great-Aunt-In-Law Gwen is one such person, and my friend Pat is another. They seem able both to understand what will appeal to the recipient and to know where to find the most suitable cards. As a regular visitor to the Ashmolean Museum in Oxford, Pat has the advantage of having available their superb range of stationery items. She never fails to send me a birthday card of the highest quality. This year, on the occasion of my sixty-third birthday, she sent me their card of Edward Stamp‘s wood engraving of a hedgehog.

63_01_Ashmolean

I decided that I would say ‘Thank you’ by making her a notebook which used the card as its front cover. Here it is, showing that Pat sees me, entirely accurately, as prickly, dormant, and somewhat endangered:

63_02_Hedgehog

Recycling Edward Stamp’s wood engraving as a book cover

This was interesting as a bookbinding project because it was the first time that I had started from the final dimensions of the book. Thus far I have always created a book-block, trimmed it, and then cut boards to fit; here I had to create a book-block that would fit the size of the card. I measured the card and allowed enough for it to wrap around a 3mm cover board; this gave the dimensions of the boards; next, I subtracted 4mm from the height and 2mm from the width of the boards to give the size of the book-block.

The next job was to prepare the manufacturer’s mark which comprised the words ‘Handmade Books by Colin Hazlehurst’. This is displayed on the last leaf of the book, so I needed to print it before collating and folding the signatures. I created six signatures of five sheets each using 90 gsm ‘Premium High White’ paper, making a notebook of 120 pages.

Then it was construction as usual: folding, stitching, trimming, glueing, and leaving to dry overnight. I added a headband and a ribbon bookmark as finishing touches.

63_03_Back

The back

63_05_EgoHocFecit

The manufacturer’s mark

63_04_Head

Rounded spine, headband, and ribbon

Copyright © Colin Hazlehurst, 2014

Written by netkingcol

May 1, 2014 at 3:06 pm

Low flying in Yosemite Valley

leave a comment »

Written by netkingcol

February 18, 2014 at 5:06 pm

Posted in Google Earth

Tagged with , , ,

Madeira – Pearl of the Atlantic

leave a comment »

Written by netkingcol

February 16, 2014 at 7:59 pm

Uluru from the air

leave a comment »

Written by netkingcol

February 12, 2014 at 5:41 pm

Learning to fly the Spirit of St. Louis

leave a comment »

This video shows the results of experiments animating a model aircraft in Google Earth. You can view the content in Google Earth here: LearningToFly.kml

Written by netkingcol

January 6, 2014 at 6:19 pm

Draw a cubic spline curve through Google Earth Placemarks

with 4 comments

Cubic Spline Demonstration

Cubic Spline Demonstration

If you want to draw a spline curve through a set of Placemarks in Google Earth, then this post might help you. I’ve written a script to achieve this (with limitations) and you are welcome to the code which is written in Javascript.

This YouTube video demonstrates the script in action:

You might want to do this, for instance, to create a path for a Camera to follow. I thought at first I would use such a curve to define the flightpath of an animated model aircraft but I realised quite soon that aircraft don’t fly along cubic splines and I needed a different approach to that problem. That’s partly why I’ve only taken the solution this far; I may come back to it later to describe how the camera flies as it follows the aircraft.

It’s not easy or elegant to post code on WordPress so I’m releasing it through Pastebin. At that link you will find an HTML file with embedded Javascript. If you want to try it for yourself you will also need a KML file which has a set of Placemarks in a Folder with id=’PlacemarkFolder’. There is a sample file on Pastebin.

All I’ve done is to bring together bits and pieces from the following resources:

Fragment 1:  initialisation

In this code fragment scripts are imported, variables defined, and Google Earth loaded. Note that in the version displayed here the spline calculations are in a separate file, whereas in the source code on Pastebin I’ve dropped them into the main script; this was purely to reduce the number of file downloads you need to get started.

Two buttons are added to the screen:

  1. A button to fetch a KML file that holds Placemarks. This could be expanded into some sort of file-open dialogue, but I haven’t done that.
  2. A button to run the spline calculation.

Line 29 is the call to create an instance of the Google Earth plugin; it names the <div> element where it should be displayed and identifies the callback function if the plugin is successfully loaded.

Line 34 calls the resize() function to maximise the size of the Earth viewer.

script001

Fragment 2:  resize the screen and initialise the plugin

Line 39 defines the function to resize the Google Earth plugin so it uses most of the available space. A little room is needed beneath the plugin to show the control buttons.

Line 50 defines the callback function which is executed after the plugin is created. The variable ‘gex’ at line 51 becomes an instance of Google Earth Extensions, which is a utility library that the script uses to navigate KML objects.

This is followed by setting up event listeners to monitor the user’s mouse, detecting mousedown, mousemove, and mouseup actions. Together these allow Placemarks to be dragged to new locations. This code was mostly copied from the Google Code Playground, but the code at lines 83 and 84 are extra. The ‘clearLineStrings’ method will remove any existing spline curves from the view, while ‘calculateSpine’ recomputes and redraws the curve based on the new Placemark positions.

script002

Fragment 3:  Fetch a KML file containing Placemarks

Line 93 defines a function to fetch and display a KML file. Line 96 sets the URL of the file. The address shown here will be valid for a while but is not guaranteed so, if you want to play with this code, you will need to copy this file (available on Pastebin), or create your own.

If the file is fetched successfully, the object returned is assigned to global variable ‘designInput’. If there’s a top-level view available, either a <LookAt> or a <Camera>, the plugin viewer navigates to that view using the code at line 106.

script003

Fragment 4:  Extract Placemarks to an array

The ‘getPlacemarks’ function, at line 111, is used to find the Placemarks in the input file and copy them to an array. Line 120 makes a call to function ‘getObjectById’. This function searches the input file for a Folder node with id set to ‘PlacemarkFolder’; this is how the input file happens to be structured; you might have other Placemarks in it but this method only operates on those that you place in the ‘PlacemarkFolder’. You can change this behaviour easily enough.

If the Folder is found, the GE Extensions API is used to find all the Placemarks it contains. Each Placemark is added to array ‘result’ which is returned to the caller.

script004

Fragment 5:  Cubic Spline Part 1

When the KML file has been loaded, you click on the ‘Fit Spline Curve’ button and this action calls the ‘calculateSpline’ function. Line 142 is where ‘getPlacemarks’ is called. If Placemarks were found, the longitude and latitude of each Placemark are extracted and added to their respective arrays (x for longitude and y for latitude). Sorry about the typo at line 144; how unprofessional 🙂

At line 160, Mr. Kuckir’s cubic spline algorithm is called to calculate the required derivatives. It is beyond my ability to describe how this works, so I’m using it as a black box of tricks (see his article for more detail).

script005

Fragment 6:  Cubic Spline Part 2

With the derivatives calculated, it is possible to generate the cubic spline curve. This will be displayed as a KmlLineString, so the first thing to do is to create a Placemark to hold the LineString geometry. Notice that the Placemark is created, at line 163, giving it a unique id which begins with the string ‘SplineCurve’. This makes it easier to remove when the input Placemarks are dragged and we want to show the new curve.

The next step is to iterate through successive pairs of Placemarks. The difference between their longitudes is calculated, and that difference is divided into 100 intermediate points (line 172). For each intermediate longitude, a latitude is calculated using the ‘CubicSpline.interpolate’ function (line 181). This point on the spline curve is added to the LineString with the function call at line 187.

When all pairs of Placemarks have been processed, the resulting curve is displayed by added the LineString Placemark to the plugin’s feature list.

script006

Fragment 7: Supporting functions

  • addToLineString adds the given point to the given LineString.
  • clearLineStrings navigates through the features added to the plugin instance and removes any Placemark that has an id beginning with ‘SplineCurve’.
  • getObjectById searches the features in the plugin for an object with the given id.

script007

Fragment 8: Completing the head element and defining the body element

There is one more function to describe; this is the addButton function which was copied from the Google Code Playground. It provides a way to add command buttons to an HTML page.

Finally, the body of the HTML page is defined. The div with id=’viewKML’ is the place where the Google Earth plugin is displayed.

script008

The script has its limitations and, in many ways, it is a first crude attempt at providing a way to draw spline curves between Placemarks. You will need to take it further if you want something more general purpose. The major limitations are:

  • The spline curve interpolation assumes that longitude is monotonically increasing; it calculates the latitude for a given longitude.
  • The script takes no account of altitude when generating the LineString; all line segments are set to an altitude of 1.0 metres.
  • No way is provided to extract the LineString coordinates.

Don’t forget, if you do download the code, I’ve commented out the URL of the KML input file and I would recommend that you create your own and place it on your own server.

Good luck, and a happy new year.

Copyright © Colin Hazlehurst, 2014

Written by netkingcol

January 2, 2014 at 2:18 pm

%d bloggers like this: