Skip to content

A small and flexible tool written in C to calculate the curvature of a route

Notifications You must be signed in to change notification settings

dasBunny/route-curvature

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

route-curvature

A small and flexible tool written in C to calculate the curvature of a route.

Takes space separated data file as input, but also includes script to convert GPX in a readable format (TODO). 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.

About

A small and flexible tool written in C to calculate the curvature of a route

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 97.1%
  • Makefile 2.9%