code: function quadratic_distance(a, b, c, dpa, dpb, orientation) {
    
    var ab = new Array(3);
    var ac = new Array(3);
    var dab2 = 0.0;
    for(var i=0; i<3; ++i) {
      ab[i] = b[i] - a[i];
      dab2 += ab[i] * ab[i];
      ac[i] = c[i] - a[i];
    }
    if(dab2 < EPSILON) {
      return 1e30;
    }
    
    //Transform c into triangle coordinate system
    var dab = Math.sqrt(dab2);
    var s = 1.0 / dab;
    var c0 = 0.0;
    for(var i=0; i<3; ++i) {
      ab[i] *= s;
      c0 += ab[i] * ac[i];
    }
    var c1 = 0.0;  
    for(var i=0; i<3; ++i) {
      c1 += Math.pow(ac[i] - c0 * ab[i], 2);
    }
    c1 = Math.sqrt(c1);
    
    //Compute center of distance field
    var dpa2 = dpa*dpa;
    var dpb2 = dpb*dpb;
    var p0 = (dpa2 - dpb2 + dab2) / (2.0 * dab);
    var p1 = dpa2 - p0*p0;
    if(p1 < 0.0) {
      return 1e30;
    }
    p1 = Math.sqrt(p1);
    if(orientation < 0) {
      p1 *= -1;
    }
    
    //Compute new distance bound
    var d = Math.sqrt(Math.pow(c0 - p0, 2) + Math.pow(c1 - p1, 2));
    
    //Return min
    return d;
    
  }
docs: Computes quadratic distance to point c