title: Interpolate points along a 3d line
body: <p>Although I outline the problem in <em>R</em>, answers in <em>R</em> and <em>Python</em> are welcome.  </p>
  
  <p>Suppose we have a set of points in x,y,z that define a discrete path (or set of connected line segments) over a vector of time t. These paths are not monotonic in z.  </p>
  
  <pre><code>path &lt;- data.frame(x = c(245, 233, 270, 400, 380),
                     y = c(245, 270, 138, 225, 300),
                     z = c(0, 1.2, 5, 3, 9),
                     t = 1:5)
  
  
  plot3D::scatter3D(path$x, path$y, path$z, type = "b", bty = "g", 
                    phi = 0, col = "red", pch = 20, ticktype = "detailed")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/S3Fq8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S3Fq8.png" alt="enter image description here"></a></p>
  
  <h1>How can I interpolate along the path at some arbitrary resolution in z?</h1>
  
  <p>For example, say I wanted to retain a resolution in z of 1 unit. The points along z are 0, 1.2, 5, 3, 9. Therefore, one possible solution that satisfies this constraint is to interpolate at 1, 2, 3, 4, 4, 4, 5, 6, 7, 8 in the z direction, yielding the blue points in the figure below (labels indicate z location):  </p>
  
  <p><a href="https://i.stack.imgur.com/OAOsa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OAOsa.png" alt="enter image description here"></a></p>
  
  <p>Ultimately, I would like the coordinates of the blue dots. We can brute force the solution by sequentially solving for the equation of the line in 3d for each pair of points z, and then interpolating along each line segment. However, I want to make sure I'm not missing some existing implementation or clever hack.  </p>