Skip to content
This repository has been archived by the owner on Feb 7, 2021. It is now read-only.

Latest commit

 

History

History
84 lines (56 loc) · 2.93 KB

README.md

File metadata and controls

84 lines (56 loc) · 2.93 KB

route-curvature

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.

Installation

$ git clone https://github.com/bluntphenomena/route-curvature.git
$ cd route-curvature
$ make

Usage

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

Example

$ ./route-curvature -s10 -i examples/maglev.dat -o examples/maglev_out.dat
$ gnuplot
gnuplot> plot "examples/maglev_out.dat" using 1:2 with lines

graph

How it works

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)

how1

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.

how2

The largest value for the radius is infinite, that is a straight line.

how3

So r is in range [d/2, ∞]. And because the curvature c = 1/r, the possible values for c are [0, 2/d]

how4

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.

how4

This is the corresponding circle with radius r=1/c with the smallest deviation.

License

        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

  1. You just DO WHAT THE FUCK YOU WANT TO.