track-simplifier1
  • master

        Simplify a polyline using various methods (radial distance, Douglas Peucker, Reuman Witkam, …).

        Example
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        
        # The polyline
        polyline   = [ {x: 1, y: 1}, {x: 5, y: 7}, ....., {x: 8, y: 1} ]
        
        # The two methods to compute distance
        # They also deal with the point structure (Array, Hash, ....)
        dist_point = ->(a,b)    {   a,b =                [a[:x],a[:y]], [b[:x],b[:y]]
                                    a,b =                Vector[*a],    Vector[*b]
                         (b - a).norm
                   }
        dist_line  = ->(p, a,b) { p,a,b = [p[:x],p[:y]], [a[:x],a[:y]], [b[:x],b[:y]]
                                  p,a,b = Vector[*p],    Vector[*a],    Vector[*b]
                         pa, ba = p-a, b-a
                         t      = pa.dot(ba)/ba.dot(ba)
                         (pa - t * ba).norm
                   }
        
        # Perform simplification
        $ts = TrackSimplifier.new(point2point: dist_point, point2line: dist_line)
        $ts.radial_distance(polyline, radius)    # Radial distance
        $ts.reumann_witkam(polyline,  threshold) # Reumann Witkam
        

        This work was supported by the Privamov project funded by LABEX IMU (ANR-10-LABX-0088) of Université de Lyon, within the program “Investissements d’Avenir” (ANR-11- IDEX-0007) operated by the French National Research Agency (ANR)