title: How to find a point in 3-D at an arbitrary perpendicular line given distance to the point
body: <p>I have a line AB. I would like to draw a line BC, perpendicular to AB. I know xyz of the points A and B, I also know the distance N between B and C. How can I find an arbitrary point C which fits into the given parameters? The calculations should be done in 3-D. Any point, perpendicular to AB can be the point C, if its distance to B equals N.</p>
  
  <p>An almost identical question is given here, but I would like to know how the same thing is done in 3-D: <a href="https://stackoverflow.com/questions/133897/how-do-you-find-a-point-at-a-given-perpendicular-distance-from-a-line">How do you find a point at a given perpendicular distance from a line?</a></p>
  
  <p>The calculation that works for me in 2-D was given in the link above: </p>
  
  <pre><code>dx = A.x-B.x
  dy = A.y-B.y
  dist = sqrt(dx*dx + dy*dy)
  dx /= dist
  dy /= dist
  C.x = B.x + N*dy
  C.y = B.y - N*dx
  </code></pre>
  
  <p>I tried adding Z axis to it like this: </p>
  
  <pre><code>dz = A.z - B.z 
  dist = sqrt(dx*dx + dy*dy + dz*dz) 
  dz /=dist 
  C.z = .... at this point it becomes a mystery to me
  </code></pre>
  
  <p>If I put something like "C.z - N*dz" into C.z, the distance is accurate only in some rotation angles, I would like to know the correct solution. I can imagine that in 3-D it is calculated in a completely different manner. </p>
  
  <p><strong>Clarification</strong></p>
  
  <ul>
  <li>Point C is not unique. It can be any point on a <em>circle</em> with its
  centre at B and radius N. The <em>circle</em> is perpendicular to AB</li>
  </ul>