Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use the <a href="http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm" rel="noreferrer">Ramer-Douglas-Peucker (RDP) algorithm</a> to simplify the path. Then you could compute the change in directions along each segment of the simplified path. The points corresponding to the greatest change in direction could be called the turning points:</p> <p>A Python implementation of the RDP algorithm can be found <a href="https://github.com/sebleier/RDP/" rel="noreferrer">on github</a>.</p> <pre><code>import matplotlib.pyplot as plt import numpy as np import os import rdp def angle(dir): """ Returns the angles between vectors. Parameters: dir is a 2D-array of shape (N,M) representing N vectors in M-dimensional space. The return value is a 1D-array of values of shape (N-1,), with each value between 0 and pi. 0 implies the vectors point in the same direction pi/2 implies the vectors are orthogonal pi implies the vectors point in opposite directions """ dir2 = dir[1:] dir1 = dir[:-1] return np.arccos((dir1*dir2).sum(axis=1)/( np.sqrt((dir1**2).sum(axis=1)*(dir2**2).sum(axis=1)))) tolerance = 70 min_angle = np.pi*0.22 filename = os.path.expanduser('~/tmp/bla.data') points = np.genfromtxt(filename).T print(len(points)) x, y = points.T # Use the Ramer-Douglas-Peucker algorithm to simplify the path # http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm # Python implementation: https://github.com/sebleier/RDP/ simplified = np.array(rdp.rdp(points.tolist(), tolerance)) print(len(simplified)) sx, sy = simplified.T # compute the direction vectors on the simplified curve directions = np.diff(simplified, axis=0) theta = angle(directions) # Select the index of the points with the greatest theta # Large theta is associated with greatest change in direction. idx = np.where(theta&gt;min_angle)[0]+1 fig = plt.figure() ax =fig.add_subplot(111) ax.plot(x, y, 'b-', label='original path') ax.plot(sx, sy, 'g--', label='simplified path') ax.plot(sx[idx], sy[idx], 'ro', markersize = 10, label='turning points') ax.invert_yaxis() plt.legend(loc='best') plt.show() </code></pre> <p><img src="https://i.stack.imgur.com/yiExE.png" alt="enter image description here"></p> <p>Two parameters were used above:</p> <ol> <li>The RDP algorithm takes one parameter, the <code>tolerance</code>, which represents the maximum distance the simplified path can stray from the original path. The larger the <code>tolerance</code>, the cruder the simplified path.</li> <li>The other parameter is the <code>min_angle</code> which defines what is considered a turning point. (I'm taking a turning point to be any point on the original path, whose angle between the entering and exiting vectors on the simplified path is greater than <code>min_angle</code>).</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload