title: Catmull-Rom interpolation on SVG Paths
body: <p>I am experimenting with creating high-performance, good-looking pencil tools using SVG paths.</p>
  
  <p>I am logging the mouse coordinates to draw a path. To get a high-fidelity path (accurate to the user's movements) I need to log a point for every pixel movement. </p>
  
  <p>Keeping each and every point in the path creates a huge amount of points which is <strong>not</strong> ideal for collaborative features later-on (sending huge amount of points back and forth is not efficient), plus parsing huge paths every time I need to manipulate them is a bottleneck</p>
  
  <p>On linear areas of the path, redundant points are removed keeping only the points necessary to represent the segment - I do this using the <a href="http://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm" rel="noreferrer">Ramer-Douglas-Peucker</a> algorithm.</p>
  
  <h2>But simplifying a path turns it into a low-fidelity polygon</h2>
  
  <p>At this point the paths are effectively just connected lines - therefore the paths look jagged.</p>
  
  <p>A possible solution is to connect the path points with Cubic Bezier's - however this doesn't work nice on simplified paths. The distance between each point is too large for the Cubic Bezier's to "sit" nice so the smoothed path no longer accurately represents the intended path of the user.</p>
  
  <p>Another solution is to simply use a "post-processing" algorithm such as <a href="https://dl.acm.org/citation.cfm?id=90941" rel="noreferrer">Schneider's Algorithm</a> on the original path - This algorithm won't practically work in real-time though since it's a performance hog</p>
  
  <h2>An ideal solution</h2>
  
  <p>A solution that(I think) could work is to use a <a href="http://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline" rel="noreferrer">Centripetal Catmull-Rom</a> interpolation.</p>
  
  <p><strong><img src="https://i.stack.imgur.com/ZuqDF.png" alt="Centripetal Catmull Rom vs rest of Catmull-Rom variants"></strong></p>
  
  <p>Out of all the algorithms I researched, this seems to be the most promising since:</p>
  
  <ol>
  <li>It doesn't create self-intersections on tight corners</li>
  <li>It fits more snug on the points thus it more accurately represents the
  original path.</li>
  </ol>
  
  <hr>
  
  <p>Is <em>Catmull-Rom</em> an algorithm that interpolates a series of
  regular x/y points or does the original path need to be comprised of
  curves?</p>