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
I've finished reading This Way Up. It's about maps, that went wrong.
It's a good read, but htyerr were several chapters that were written in a novel way (as a video transcript, a series of letters), and I found distracting from the a tail content. It'll have worked better in a produced video.
No mention of @openstreetmap though :-(
Updated a bench
Created a tree; Updated 3 humps and a waste_basket
The Early Cormorant Catches the Eel
Sorry, not the best photo! But I caught this Cormorant catching this large eel when looking for Bank Swallows, right next to Eel Pie Island in the Thames.
#Birds #BirdPhotography #BirdsOfMastodon #Photography #London
Updated an estate_agent office
I went to my nieces' birthday party yesterday.
The theme was pink, and that included all the food, mostly died with beet root.
Shock and horror this morning when doing number two. Not only was my turd dark red, it was also glittering at me. Apparently the carrot cake had edible glitter...
So now I know what's worse than glitter.
😂 ✨ 💩 🟣Long-Tailed Tit on a Branch with Lichen
I've been spending some time in random London local nature reserves.
Sitting and listening, and in fifteen minutes you spot countless species.
This one was in Ham Lands Local Nature Reserve near Teddington.
#london #BirdPhotogaphy #BirdsOfMastodon #Birds #LichenSubscribe
A Colourful Mandarin
In The Long Water in Kensington Palace Gardens, London.
Created 7 benches
Created 2 benches
Created a bench
I walked 7.3km in 2h28m39s
Added a note about a duplicate Papersmiths
I walked 4.1km in 49m02s
Fixed website
fix typo
Updated a bench
I walked 1.6km in 20m26s
I walked 1.1km in 11m49s
The Yellow Eye
A blue heron's head, with its very yellow stare-y eye.
#BirdPhotography #Photography #BirdsOfFediverse #BirdsOfMastodon #London
My little Lego box is telling me it really is quite warm outside.
Created a bicycle_parking and a crossing
I walked 3.3km in 41m56s








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