A small and flexible tool written in C to calculate the curvature of a route.
Takes space separated data file as input. Output is a space separated data file as well, ready to be plotted by gnuplot or similar software.
$ git clone https://github.com/bluntphenomena/route-curvature.git
$ cd route-curvature
$ make
route-curvature [options] -i file
Options:
-h, --help prints this help message and exit
-s, --smoothness number of points to calculate curvature from.
The more points, the smoother the output gets.
(Default value: 5)
-t treat input values as cartesic coordinates instead of
using mercator projection on geographic coordinates
-i, --input input file
-o, --output output file
$ ./route-curvature -s10 -i examples/maglev.dat -o examples/maglev_out.dat
$ gnuplot
gnuplot> plot "examples/maglev_out.dat" using 1:2 with lines
Let d be the distance between the first and last point of a route segment consisting of n points. (n can be modified with the --smoothness
option)
Find a circle with radius r that goes best through the points of the route segment. The smallest possible radius is half of the distance between the first and last point.
The largest value for the radius is infinite, that is a straight line.
So r is in range [d/2, ∞]. And because the curvature c = 1/r, the possible values for c are [0, 2/d]
A model graph of how the deviation between the route segment and the circle depends on the curvature.
The value c with the lowest deviation can be found by searching for the local minimum.
This is the corresponding circle with radius r=1/c with the smallest deviation.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar 14 rue de Plaisance, 75014 Paris, France Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- You just DO WHAT THE FUCK YOU WANT TO.