Orientation to a Quadratic Bezier Curve

Something I made as an answer to a question in the AS forum. It’s nothing too special but should be helpful for people wanting to work directly with quadratic bezier curves. The quadratic bezier curve derivative is used in this example to find the slope of a tangent to the curve, but it can also be used to find things such as curve length.

Example (source attached)

These are the two important functions:

function quadBezCurve(p0:Number, p1:Number, p2:Number, t:Number):Number {
	var d:Number = 1 - t;
	return d * d * p0 + 2 * t * d * p1 + t * t * p2;
}
function quadBezCurveDeri(p0:Number, p1:Number, p2:Number, t:Number):Number {
	return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
}

There’s also the math in the example which finds the value of t for the parametrization of the curve from an input value of x. Note however that if curve cannot be expressed as a function (ie there is two outputs for a single input) then the math will fail as there is no way to tell which output you want.