Smoothing lines with splines
For my OpenStreetMap year of edits videos I use PovRay to animate edits of OpenStreetMap. Over the course of a year I show all the edits that have been made. In previous years, I used a simple sine function to rotate the Earth alone it's North/South and East/West axises. This year I wanted to highlight specific events so I needed a different method to rotate the Earth.
I started out with finding events and created two paths for them:
This one starts in Greenland, moves towards Brazil and then heads over Russia, India, the Philippines and ends in Indonesia.
The second one starts in Korea, moves through Africa, heads towards Antarctica and then heads back to France over Brazil.
Each of the two paths have points highlighted which are (about) 15 days apart. The paths I converted into data files, which look like
0000 -24 70 8500 0180 -64 58 9500 0240 -81 29 10000 0480 -43 -16 15000 0720 -8 36 20000 0840 27 44 15000 1020 76 20 15000 1140 115 25 15000 1320 127 -2 9000 1460 157 -24 10000
The first column is the frame number (four frames per day), then the longitude and the latitude and finally the height of the camera over the point. As you can see, I have not included a line for each of the points in the path images.
From the points in the data files, I then needed to generate all the intermediate points for each of the three columns. And my first (naive) attempt was to simply do a linear interpolation. Point 1's longitude can be calculated by: -24 + (1-0) * ((-64 - -24) / (180 - 0)) and point 856's longitude with: 27 + (855 - 840) * ((76 - 115) / (1020 - 840)). Doing that for all of the three axis (for the first 300 frames) results in the following video:
As you can see, the changes in direction (and height) are really abrupt, and doesn't make for a nice smooth rotating body. So I had to come up with something else: a smoothed line.
There are various different ways of smoothing line, but one of the easier ones that I found was the Spline. A spline is a smoothing function that connects all the data points with sufficiently smooth curves. I used the implementation at http://www.script-tutorials.com/smooth-curve-graphs-with-php-and-gd/ with the other script available through https://github.com/derickr/osm-year-in-edits/blob/master/changes/create-camera-from-file.php
If we now look at the same section of the video, we see that the turns and zoom level are much smoother:
Just focussing on the zoom aspect, I am also reproducing a line graph of the interpolated points here:
As you can see, between 1172 and 1328 it makes a very big dip—and that wrecked with my video as it zoomed in too much. I've fixed that manually for the video, but I would like to find an algorithm that did produce smooth lines without such a big "dip". Any ideas are most welcome.
Comments
Maybe the easiest solution is to insert a "correcting dot" at about (1300, 8000)?
Since your point at the right of 1328 is so far "off", it causes the line to do a small dip at the left of 1328. I'd still call it small, compared to the offset of your last point...
Moving average could help, even if "noises" appear anywhere in the data set:
Catmull–Rom spline should do what you want: http://en.wikipedia.org/wiki/Hermite_curve#Catmull.E2.80.93Rom_spline
Life Line
Merged pull request #1055
Fixed issue #2387: Remove INI entries for changed and removed Xdebug …
Merged pull request #1053
Reimplement PR #1052 with normal style
Add missing section comment
Merge branch 'xdebug_3_5'
Merged pull request #1054
Change error retrieval method in ctrl_socket.c
Pink Sky at Sunset
I took this photo over the Christmas period in the Dutch city of Breda.
I walked 8.5km in 1h25m28s
I walked 8.1km in 1h21m10s
I walked 0.8km in 9m03s
I walked 4.8km in 50m12s
Went for a 20k walk through Bushy Park, along the Thames, and through Richmond Park and Wimbledon Common. It was a bit nippy!
I hiked 19.3km in 3h52m02s
Updated a pub
I walked 4.6km in 44m50s
I walked 4.9km in 47m58s
Update Westbourne Green area, now that it is open
I walked 11.9km in 2h3m03s
I walked 9.8km in 1h47m38s
I walked 10.2km in 1h34m25s
Whoop! FOSDEM travel and hotel booked. See you in Brussels at the end of January?
I walked 10.6km in 1h48m23s
I walked 3.0km in 33m38s



Shortlink
This article has a short URL available: https://drck.me/spline-au2