# Finding the formula for Bezier curve ratios (hull/point : point/baseline)

Given a cubic Bezier curve defined by points p₁, p₂, p₃, and p₄, a point B on that curve at some t value (where 0 ≤ t ≤ 1), a point A on the line (p₂p₃) at distance ratio t from p₂, and a point C that is the intersection of the line (p₁p₄) and the line that goes through A and B, the ratio between distance d1 = (AB) and d2 = (BC) is a fixed value, regardless of the values for coordinates p₁, p₂, p₃, and p₄

I'd like to find the formula that expresses this ratio as a function of t (all interactive graphing experiments suggest that this function is an identity function for cubic Bezier curves, not actually being dependent on the coordinates used for the curve) but I'm having little success coming up with something satisfactory. My math skills are not sufficient...

I initially wrote up a quick data-generator using the "Processing" programming language to see if I could use that data for polynomial regression (based on the fact that the function is symmetrical around t = 0.5, finding the expression for the interval t=0.5 to t=1), but the fact that the ratio is actually asymptotic at t = 0 and t = 1 (towards positive infinity) means that it's not a straight-forward power function.

.

(note: the jsfiddle link doesn't actually log all 5000 step values; normal Processing does)

Would anyone know how to express this ratio function as a proper formula? I don't quite know how to approach this symbolically, as I'm using de Casteljau's algorithm to determine my red and green lines; since I don't know how to symbolically express the values d1 and d2, expressing the ratio d1/d2 as a function is quite hard.

N.B.: Apologies if the tags don't fit the question. I'll take suggestions on using the right ones instead; first question on MathOverflow.

-

A cubic bezier defined by $p_1, p_2, p_3, p_4$ has parametric equation $$B(t) = (1-t)^3p_1 + 3(1-t)^2tp_2 + 3(1-t)t^2p_3 + t^3p_4.$$

The setup here also defines $A(t) = (1-t) p_2 + tp_3$.

The way $C$ is defined, there are some real $s(t)$ and $u(t)$, both possibly depending on $p_1,\ldots,p_4$ such that $C = sA + (1-s)B = up_1 + (1-u)p_4$.

So $B - C = B - sA - (1-s)B = s(B-A)$. Hence $\frac{|B - C|}{|A - B|} = |s|$.

On the other hand, we want $sA + (1-s)B - up_1 - (1-u)p_4 = 0$. That comes out to

$$((1-s)(1-t)^3 - u)p_1 + (s(1-t) + 3(1-s)t(1-t)^2)p_2 + (st + 3(1-s)t^2(1-t))p_3 + ((1-s)t^3 - (1-u))p_4 = 0.$$

Set $$s = \frac{t^3+(1-t)^3-1}{t^3 + (1-t)^3}$$ and $$u = \frac{(1-t)^3}{t^3 + (1-t)^3}.$$

Then the coefficents of $p_1,\ldots,p_4$ in the above expression become identically 0. Note that the denominators of these expressions are never 0 for $t \in [0,1]$, so the divisions are ok.

So your ratio is given by the $|s|$ above (or its reciprocal, depending on how you're taking the ratio).

-
you are a hero, thanks! –  Mike 'Pomax' Kamermans Feb 19 '13 at 18:34

Just in case someone finds this question using google at some point, and is also curious about the solution for the quadratic case, its solution is similar:

$A(t) = p_2$

$B(t) = (1-t)^2p_1 + 2t(1-t)p_2 + t^2p_3$

$C(t) = sA(t) + (1-s)B(t) = up_1 + (1-u)p_2$

This requires solving:

$$sp_2 + (1-s)((1-t)^2p_1 + 2t(1-t)p_2 + t^2p_3) - up_1 + (1-u)p_2 = 0$$

which, expressed in terms of the control points, is:

$$((1-s)(1-t)^2 - u)p_1 + (s+2t(1-s)(1-t))p_2 + ((1-s)t^2 + u - 1)p_3 = 0$$

If we want these coefficients to become identically zero, we can determine s(t):

$$(1-s)(1-t)^2 = u = -((1-s)t^2 - 1)$$

which means solving:

$$(1-s)(1-t)^2 + ((1-s)t^2 - 1) = 0$$

which gives us the following expressions for s and u (after substituting s into either of the identities for u and solving):

$$s(t) = \frac{2t^2 - 2t}{2t^2 - 2t + 1}$$

$$u(t) = \frac{(t-1)^2}{2t^2 - 2t + 1}$$

(Also note that there are no solutions for curves of order 4 and higher; unlike for quadratic and cubic curves, the ratio between the two distances is not a fixed value for higher order curves, unfortunately)

-