title: How to get a fixed number of evenly spaced points describing a path?
body: <p>Given is a path described by an ordered array of points (x,y). I'm looking for an algorithm that describes this path with a given number of points (k) that are evenly spaced along the path.</p>
  
  <p><strong>Input points</strong>:</p>
  
  <pre><code>[[x1,y1], ..., [xn,yn]] (randomly spaced)
  </code></pre>
  
  <p>Where <em>x1,y1</em> is the first waypoint and <em>xn,yn</em> the last. The path is defined by connecting every point to the next with a straight line.</p>
  
  <pre><code>(Xn,Yn) -----&gt; (Xn+1,Yn+1)
  </code></pre>
  
  <p><strong>Expected output</strong>:</p>
  
  <pre><code>[[x1,y1], ..., [xk,yk]] (evenly spaced)
  </code></pre>
  
  <p><a href="http://i.imgur.com/ISqiHjc.png" rel="nofollow">Image of an example path</a></p>
  
  <p><strong>Update:</strong> I've looked at Ramer-Douglas-Peucker algorithm. It will reduce the number of points but it won't allow to set a fixed number of points and they are not evenly spaced.</p>