1
$\begingroup$

A quadratic Bézier curve is defined by three points in 3D, $P_0$, $P_1$, and $P_2$. The equation for the Bézier curve is defined through the parameterization of $t$, which has the range $0\leq t\leq 1$, and is as follows: $$B(t)=P_0 (1-t)^2+2P_1 (1-t)t+P_2 t^2$$.

We can calculate the total length of this curve, $l$, along the parameterization as follows: $$l=\int_0^1B(t)dt=\int_0^1 P_0 (1-t)^2+2P_1 (1-t)t+P_2 t^2 dt=\int_0^1 P_0 (1-2t+t^2) + P_1(2t-2t^2) + P_2(t^2) dt$$

This is a fairly easy integral to calculate, as $P_i$ is independent of t, and the rest is very simple. In the end, this becomes $$l=P_0([t]_0^1 -2[t/2]_0^1 + [2t/3]_0^1) + P_1([2t^2/2]_0^1-[2t^3/3]_0^1) + P_2([2t^2/3]_0^1)=\frac{2}{3}P_0 + \frac{1}{3}P_1 + \frac{2}{3}P_2$$

The trouble I am having now is how to convert this into a scalar with a physical meaning.

The thing I first considered was just doing $$\sqrt{(\frac{2}{3}P_0.x + \frac{1}{3}P_1.x + \frac{2}{3}P_2.x)^2 + (\frac{2}{3}P_0.y + \frac{1}{3}P_1.y + \frac{2}{3}P_2.y)^2 + (\frac{2}{3}P_0.z + \frac{1}{3}P_1.z + \frac{2}{3}P_2.z)^2}$$

This may be the correct thing to do, but I don't have a good way of proving it one way or the other, and it doesn't make strong intuitive sense to me.

The other way I could go about it is do the process of calculating $l$ for each dimension within the integral, so that I'd end up with an $l_x, l_y, l_z$, but then I'm still not sure what to do within there.

$\endgroup$
2
  • $\begingroup$ It is well known that finding the arc length of a parabola is difficult, so that would apply to this. $\endgroup$ Commented Oct 3 at 22:26
  • $\begingroup$ The man's name is Bézier. Not Bezier. And I think he deserves capitalization. I fixed the post for you. $\endgroup$ Commented Oct 3 at 23:53

2 Answers 2

1
$\begingroup$
  1. Your formula for the Bezier curve is wrong. You can tell that by considering the case where $P_0 = P_1 = P_2$. With the proper formula, you'd get a constant curve that sits at location $P_0$, i.e., the sum of the coefficients would be the constant polynomial $1$. It's not, and that's because you lost the factor of $2$ in the middle term. It should be $$ B(t)=P_0 (1-t)^2+ 2 P_1 (1-t)t+P_2 t^2. $$

  2. Even after that fix, your formula for the length is completely wrong. You need to integrate the length of the tangent vector over the domain, i.e., to compute \begin{align} L &= \int_0^1 \|B'(t)\|~dt\\ &= \int_0^1 \|-2P_0(1-t) + 2P_1(1-2t) + 2 P_2 t\|~dt\\ &= \int_0^1 \| -2P_0 + 2 P_1 +2P_0 t - 4P_1 t + 2 P_2 t \|~dt\\ &= 2\int_0^1 \| (P_1 - P_0) + t(P_0 + P_2 - 2 P_1) \|~dt\\ \end{align} Calling the two point-differences $u = P_1 - P_0$ and $v = P_2 - P_1$, and then $w =v - u$ makes this a little simpler: \begin{align} L &= 2\int_0^1 \| u + tw \|~dt\\ &= 2\int_0^1 \left( (u + tw)\cdot (u + tw) \right)^\frac12~dt\\ &= 2\int_0^1 \left( u \cdot u + 2 t u \cdot w + t^2 w \cdot w \right)^\frac12~dt\\ \end{align} ...which turns out to be a messy integral.

I've probably screwed up the algebra above somewhere -- it's early morning! -- but the gist is that the arclengths for Bezier curves don't have a pretty form in general (although the degree-1 Bezier curve does, of course).

$\endgroup$
1
  • $\begingroup$ Good catch with the incorrect formula there! I had done all my work on the page with the correct formula and just typed it out wrong, so I will correct that. Thank you for the insight on the tangent vector, I think that was the piece I was really missing here, it makes a lot more sense! $\endgroup$ Commented Oct 3 at 18:48
0
$\begingroup$

The answer from John Hughes has most of what you need. According to various clever computer systems, the "messy integral" that he refers to is ... $$ \int_0^1 \sqrt{a t^2 + b t + c}\, dt = \frac{2 a + b}{4a}\sqrt{a + b + c} - \frac{b}{4a}\sqrt{c} + \frac{4ac - b^2}{8 a^{3/2}} \ln\!\left( \frac{ 2\sqrt{a}\sqrt{a + b + c} + 2 a + b }{ 2\sqrt{a}\sqrt{c} + b } \right) $$ Of course, this only works if $a$, $c$ and $a+b+c$ are all non-negative, but I think that is always true here.

If you don't want to mess with big hairy formulas like this, you can just approximate your Bézier curve with a polyline, and measure that instead. That will work for Bézier curves of any degree. Also, by adjusting the number of segments in the polyline, you can make trade-offs between performance and accuracy.

$\endgroup$
5
  • $\begingroup$ When you say polyline, what exactly do you mean? It seems to be a term that can somewhat vary with context, so if you could be a little more specific that would be appreciated. The idea of approximation is intriguing to me, so I'd like to understand more about what you mean $\endgroup$ Commented Oct 6 at 1:23
  • $\begingroup$ When I say polyline, I mean a sequence of (typically short) line segments that join end-to-end. It’s pretty standard terminology. $\endgroup$ Commented Oct 7 at 3:58
  • $\begingroup$ That part made sense, but it seems that some conceptalizations of polyline include curves (which seems to me to run into the same issue underlying the Bezier solution in the first place), while others include only straight segments. It seems you meant only straight line segments, but I wanted to make sure $\endgroup$ Commented Oct 7 at 8:05
  • 1
    $\begingroup$ You can also approximate somewhat more rapidly, but with trickier algorithms, using a poly-arc, to coin a term -- a sequence of joined segments and circle arcs. As with polylines, computing the total length of a polyarc is quick, and gives a decent estimate for the length of a Bézier curve. $\endgroup$ Commented Oct 13 at 9:54
  • $\begingroup$ Yes. What @JohnHughes said. Look up the term bi-arc if you want to try this. $\endgroup$ Commented Oct 13 at 11:53

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.