title: Calculate the angle between 2 segments in 3D space with plain python
body: <p>I have two segments in a 3D space defined by the coordinates of their starting and ending points.</p>
  
  <p>I need to calculate the angle between these two segments in python without numpy or other fancy libs.</p>
  
  <p>I wrote the following code, which seems correct to me:</p>
  
  <pre><code>def CalcAngle(beg1, end1, beg2, end2):
  
    vect1 = [None, None, None]
    vect2 = [None, None, None]
  
    for cc in range(3):
      vect1[cc] = end1[cc] - beg1[cc]
      vect2[cc] = end2[cc] - beg2[cc]
  
    length1 = math.sqrt(vect1[0]**2+vect1[1]**2+vect1[2]**2)
    length2 = math.sqrt(vect2[0]**2+vect2[1]**2+vect2[2]**2)
  
    dotProd = 0.0
    for cc in range(3):
      dotProd += (vect1[cc] * vect2[cc])
  
    angleRad = math.acos( dotProd / (length1 * length2) )
    angleDeg = math.degrees(angleRad)
  
    return angleRad, angleDeg
  
  # 1st segment
  beg1 = [47.737, 31.8, 21.762]
  end1 = [43.55, 38.956, 42.209]
  
  # 2nd segment 
  beg2 = [35.993, 18.033, 56.988]
  end2 = [31.497, 18.783, 68.881]
  
  angleRad, angleDeg = CalcAngle(beg1, end1, beg2, end2)
  
  # angleRad is 0.312973304876
  # angleDeg is 17.9320494697
  </code></pre>
  
  <p>Am I missing something here?
  Is there any situation where my code will not work ?</p>
  
  <p>Thank you.</p>