transfer Quadratic Bezier Curve to Cubic Bezier Curve

@param  {number} a abscissa of p1
@param  {number} b ordinate of p1
@return {Array} parameter matrix for cubic bezier curve
like [[p1x, p1y], [p2x, p2y]]
187160
function quadratic2cubicBezier (a, b) {
  return [
    [
      (a / 3 + (a + b) / 3 - a) / (b - a),
      (a * a / 3 + a * b * 2 / 3 - a * a) / (b * b - a * a)
    ], [
      (b / 3 + (a + b) / 3 - a) / (b - a),
      (b * b / 3 + a * b * 2 / 3 - a * a) / (b * b - a * a)
    ]
  ]
}
226777
function getPointOnBezier(startX, startY, cpX, cpY, endX, endY, distance){
    var bestT = 0;
    var bestAccuracy = 1000;
    var stepSize = 0.001;
    for(var t = 0; t<1; t+=stepSize){
      var currentPoint = getQuadraticCurvePoint(startX, startY, cpX, cpY,
          endX, endY, t);
      var currentDistance = getDistanceBetweenPoints(startX, startY,
          currentPoint.x, currentPoint.y);
      if(Math.abs(currentDistance-distance) < bestAccuracy){
        bestAccuracy = Math.abs(currentDistance-distance);
        bestT = t;
      }
    }
    return getQuadraticCurvePoint(startX, startY, cpX, cpY, endX, endY, bestT);
  }
1332320
function sampleCubicBézier(x0, y0, x1, y1, x2, y2, x3, y3) {
		// Calculate all the mid-points of the line segments
		const x01   = (x0 + x1) / 2,
		      y01   = (y0 + y1) / 2,
		      x12   = (x1 + x2) / 2,
		      y12   = (y1 + y2) / 2,
		      x23   = (x2 + x3) / 2,
		      y23   = (y2 + y3) / 2,
		      x012  = (x01 + x12) / 2,
		      y012  = (y01 + y12) / 2,
		      x123  = (x12 + x23) / 2,
		      y123  = (y12 + y23) / 2,
		      x0123 = (x012 + x123) / 2,
		      y0123 = (y012 + y123) / 2;

		// Try to approximate the full cubic curve by a single straight line
		const dx = x3-x0,
		      dy = y3-y0;

		const d1 = Math.abs(((x1-x3)*dy - (y1-y3)*dx)),
		      d2 = Math.abs(((x2-x3)*dy - (y2-y3)*dx));

		if (((d1+d2)*(d1+d2)) < (tolerance2 * (dx*dx + dy*dy))) add(x0123,y0123);
		else { // Continue subdivision
		  sampleCubicBézier(x0, y0, x01, y01, x012, y012, x0123, y0123); 
		  sampleCubicBézier(x0123, y0123, x123, y123, x23, y23, x3, y3); 
		}
   }
102896
function ( vectorA, vectorB, vectorC ) {

		var a, b, c,
			point = new THREE.Vector3(),
			tmp = THREE.GeometryUtils.__v1;

		a = THREE.GeometryUtils.random();
		b = THREE.GeometryUtils.random();

		if ( ( a + b ) > 1 ) {

			a = 1 - a;
			b = 1 - b;

		}

		c = 1 - a - b;

		point.copy( vectorA );
		point.multiplyScalar( a );

		tmp.copy( vectorB );
		tmp.multiplyScalar( b );

		point.addSelf( tmp );

		tmp.copy( vectorC );
		tmp.multiplyScalar( c );

		point.addSelf( tmp );

		return point;

	}
1222093
function calculateBezier(t, p0, p1, p2, p3) {
  var mt = 1 - t;
  return mt * mt * mt * p0 + 3 * mt * mt * t * p1 + 3 * mt * t * t * p2 + t * t * t * p3;
}
107290
function distanceAAShapes(shapeA, shapeB) {
    const dx = Math.max(Math.abs(shapeA.pos.x - shapeB.pos.x) - ((shapeA.w / 2) + (shapeB.w / 2)), 0);
    const dy = Math.max(Math.abs(shapeA.pos.y - shapeB.pos.y) - ((shapeA.h / 2) + (shapeB.h / 2)), 0);
    return Math.sqrt(dx * dx + dy * dy);
}
294778
function curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3) {
    // in the current line style, draw a bezier curve from (x0,y0) to (x3,y3) using the other two points
    // as the control points for the curve.
    $this->objects[$this->currentContents]['c'] .=
      sprintf("\n%.3F %.3F m %.3F %.3F %.3F %.3F %.3F %.3F c S", $x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3);
  }
396630
function ( vectorA, vectorB, vectorC ) {

		var s, a, b, c,
			tmp = THREE.GeometryUtils.__v1;

		tmp.sub( vectorA, vectorB );
		a = tmp.length();

		tmp.sub( vectorA, vectorC );
		b = tmp.length();

		tmp.sub( vectorB, vectorC );
		c = tmp.length();

		s = 0.5 * ( a + b + c );

		return Math.sqrt( s * ( s - a ) * ( s - b ) * ( s - c ) );

	}
810769
def drawCurve(self, p1, p2, p3):
        
        kappa = 0.55228474983
        p1 = Point(p1)
        p2 = Point(p2)
        p3 = Point(p3)
        k1 = p1 + (p2 - p1) * kappa
        k2 = p3 + (p2 - p3) * kappa
        return self.drawBezier(p1, k1, k2, p3)
676595
function outer(A, B) {
    if (A.shape.length === 1) {
        A.reshape([A.shape[0], 1]);
    }
    else if (A.shape.length === 2) {
        if (A.shape[1] !== 1) {
            throw new Error('A is not a column vector');
        }
    }
    else {
        throw new Error('A has invalid dimensions');
    }
    if (B.shape.length === 1) {
        B.reshape([1, B.shape[0]]);
    }
    else if (B.shape.length === 2) {
        if (B.shape[0] !== 1) {
            throw new Error('B is not a row vector');
        }
    }
    else {
        throw new Error('B has invalid dimensions');
    }
    if (A.shape[0] !== B.shape[1]) {
        throw new Error('Sizes of A and B are not compatible');
    }
    return matmul(A, B);
}
762492
def translate(curve, z0):
    """"""
    if isinstance(curve, Path):
        return Path(*[translate(seg, z0) for seg in curve])
    elif is_bezier_segment(curve):
        return bpoints2bezier([bpt + z0 for bpt in curve.bpoints()])
    elif isinstance(curve, Arc):
        new_start = curve.start + z0
        new_end = curve.end + z0
        return Arc(new_start, radius=curve.radius, rotation=curve.rotation,
                   large_arc=curve.large_arc, sweep=curve.sweep, end=new_end)
    else:
        raise TypeError("Input `curve` should be a Path, Line, "
                        "QuadraticBezier, CubicBezier, or Arc object.")
525411
function curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3)
    {
        // in the current line style, draw a bezier curve from (x0,y0) to (x3,y3) using the other two points
        // as the control points for the curve.
        $this->addContent(
            sprintf("\n%.3F %.3F m %.3F %.3F %.3F %.3F %.3F %.3F c S", $x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3)
        );
    }
1222773
function sCurve(length, rotation) {
    var curve = new Float32Array(length),
        i,
        phase = rotation > 0 ? Math.PI / 2 : -(Math.PI / 2);

    for (i = 0; i < length; ++i) {
        curve[i] = Math.sin(Math.PI * i / length - phase) / 2 + 0.5;
    }
    return curve;
}
912910
def transform(curve, tf):
    """"""
    def to_point(p):
        return np.array([[p.real], [p.imag], [1.0]])

    def to_vector(z):
        return np.array([[z.real], [z.imag], [0.0]])

    def to_complex(v):
        return v.item(0) + 1j * v.item(1)

    if isinstance(curve, Path):
        return Path(*[transform(segment, tf) for segment in curve])
    elif is_bezier_segment(curve):
        return bpoints2bezier([to_complex(tf.dot(to_point(p)))
                               for p in curve.bpoints()])
    elif isinstance(curve, Arc):
        new_start = to_complex(tf.dot(to_point(curve.start)))
        new_end = to_complex(tf.dot(to_point(curve.end)))
        new_radius = to_complex(tf.dot(to_vector(curve.radius)))
        return Arc(new_start, radius=new_radius, rotation=curve.rotation,
                   large_arc=curve.large_arc, sweep=curve.sweep, end=new_end)
    else:
        raise TypeError("Input `curve` should be a Path, Line, "
                        "QuadraticBezier, CubicBezier, or Arc object.")
46783
def curve(bez, draw)
      x1, y1, cx1, cy1 = bez.x1, bez.y1, bez.cx1, bez.cy1
      cx2, cy2, x2, y2 = bez.cx2, bez.cy2, bez.x2, bez.y2
      use_cairo do |cc|
        cc.move_to(x1, y1)
        cc.curve_to(cx1, cy1, cx2, cy2, x2, y2)
        cc.fill_n_stroke(draw)
      end
    end
560250
def pts_on_bezier_curve(P=[(0.0, 0.0)], n_seg=0):
    '''
    '''
    assert isinstance(P, list)
    assert len(P) > 0
    for p in P:
        assert isinstance(p, tuple)
        for i in p:
            assert len(p) > 1
            assert isinstance(i, float)
    assert isinstance(n_seg, int)
    assert n_seg >= 0
    
    return [pt_on_bezier_curve(P, float(i)/n_seg) for i in range(n_seg)] + [P[-1]]
1191388
function(g, x, y, width, height, radius) {
        g.beginPath();
        // a
        g.moveTo(x + width / 2, y);
        // b
        g.bezierCurveTo(//
        x + width / 2 + radius / 2, y, //
        x + width / 2 + radius, y + radius / 2, //
        x + width / 2 + radius, y + radius);
        // c
        g.bezierCurveTo( //
        x + width / 2 + radius, y + radius * 2, //
        x + width / 2, y + height / 2 + radius / 3, //
        x + width / 2, y + height);
        // d
        g.bezierCurveTo(//
        x + width / 2, y + height / 2 + radius / 3, //
        x + width / 2 - radius, y + radius * 2, //
        x + width / 2 - radius, y + radius);
        // e (a)
        g.bezierCurveTo(//
        x + width / 2 - radius, y + radius / 2, //
        x + width / 2 - radius / 2, y + 0, //
        x + width / 2, y + 0);
        g.closePath();
    }