Curly Curves
https://ninjakoa.la/curly_curves/
Recent content on Curly CurvesHugo -- gohugo.ioen-usWed, 17 Jul 2024 00:00:00 +0000Bézier curve arc length parametrizations
https://ninjakoa.la/curly_curves/posts/quadratic_bezier_arc_length_parametrization/
Wed, 17 Jul 2024 00:00:00 +0000https://ninjakoa.la/curly_curves/posts/quadratic_bezier_arc_length_parametrization/<p>Bézier curves are widely used for defining vector graphics. They are basically polynomial parametric curves, but given in the Bernstein basis, which enables us to define the curve using control points. The first and last control point define the start and endpoint of the curves, the intermediate control points kind of bend the curve. The two types of Bézier curves which are generally used are quadratic and cubic Bézier curves. Quadratic Bézier curves are given by three control points, cubic Bézier curves by four. If you want to know more, <a href="https://en.wikipedia.org/wiki/B%C3%A9zier_curve">Wikipedia</a> is a good starting point.</p><h1 id="arc-lengths">Arc lengths</h1><figure class="mid"><img src="https://ninjakoa.la/curly_curves/arc_lengths.svg" alt="Two cubic Bézier curves with different arc lengths"><figcaption> <p>Two cubic Bézier curves with different arc lengths</p> </figcaption></figure><p>The arc length of a curve is the distance traveled when moving along the curve from start to end.It is well known in the computer graphics community that the arc length of cubic Bézier curves has no closed form and has to be computed numerically. Sadly, I’ve not yet seen a proof sketch for that, though. Most people just link to the <a href="https://en.wikipedia.org/wiki/Abel%E2%80%93Ruffini_theorem">Abel-Ruffini theorem</a>, but that is not directly applicable as far as I know. I’ll leave the challenge of proving that to a later post and deal with the quadratic Bézier curves for now. The arc length of quadratic Bézier curves actually can be computed with a closed form expression. It is also possible to compute the arc length \(l(t)\) up to some point on the curve given by the parameter \(t\). However, oftentimes you want to have an arc length parametrization, that is a parametrization that maps a parameter \(s\) to the point on the curve that is an arc length of \(s\) apart from the start. That amounts to computing the inverse of \(l(t)\). The arc length parametrization of a quadratic Bézier is also generally accepted to have no closed form solution, but I’ve also not seen a proof for that before.</p><p>In this post, I will show that, assuming Schanuel’s conjecture, indeed no such formula exists.Don’t worry if you’re not so deep into abstract math, I’m basically applying some substitutions to bring the relevant expression into a form where I can use a known result. Also, I’m trying my best to make this post easy to follow. I’m assuming you know how to do calculations like integration, and how to use the exponential function \(\exp\) and the natural logarithm \(\log\), though.</p><h1 id="but-how-to-prove-that">But how to prove that?</h1><p>At first glance, I had no idea how to tackle that.I’ve learned some Galois theory, which enables you to prove that a polynomial has no solution in radicals (the nth roots), but that is clearly not immediately applicable here. Hence, I used my favorite search engine and found this: <a href="https://math.stackexchange.com/a/4223360">https://math.stackexchange.com/a/4223360</a>.I was delighted that someone gave such a nice overview over the topic and started to look into the papers by Lin and Chow. Chow actually used Lin’s result to prove there is no closed form solution for \(x+e^x = 0\) and then proves that polynomials which can’t be solved by radicals also can’t be solved by using \(\log\) and \(\exp\). All those results are conditional, though and assume Schanuel’s conjecture.</p><p>Schanuel’s conjecture is widely believed to be true, but seems pretty hard to prove.It basically says that there is no nontrivial polynomial relationship between the numbers \(\alpha\) and\(e^\alpha\). For all the details, see <a href="https://en.wikipedia.org/wiki/Schanuel%27s_conjecture">Wikipedia</a>.</p><p>Looking at Lin’s result, I thought it looked promising for proving the nonexistence of a closed form arc length parametrization. Of course, it’s a bummer that it depends on an unproven conjecture, but well.I will resort to accepting Schanuel’s conjecture to be true, otherwise the desired result is probably out of reach.</p><p>OK, let’s start digging into the math:</p><h1 id="some-prerequisites">Some prerequisites</h1><p>First of all, \(\mathbb{Q}\) are the <strong>rational numbers</strong>: all numbers that can be expressed as a fraction of two integers, for example: \(\frac{1}{2}\), \(-\frac{3}{2}\), \(5=\frac{5}{1}\), and so on.</p><p>Next we have the <strong>polynomials</strong> over \(\mathbb{Q}\):The polynomials in one variable \(x\) are denoted by \(\mathbb{Q}[x]\), examples include: \(x^2+1\) or \(x^3-\frac{x}{2}+\frac{1}{5}\). Additionally, \(\mathbb{Q}[x,y]\) are the polynomials in the two variables \(x\) and \(y\), like \(x^2+y^2-1\) or \(\frac{x+y}{2}\).</p><p>A polynomial \(p\) is called <strong>irreducible</strong>, if there are no non-constant polynomials \(f\) and \(\)gsuch that \(p = f \cdot g\). The irreducible polynomials can be seen as an analog of prime numbers for polynomials.</p><p>Now, let’s take a look at the <strong>algebraic numbers</strong> \(\overline{\mathbb{Q}}\): all numbers that are roots of a polynomial with rational coefficients. This includes all rational numbers: Let \(a \in \mathbb{Q}\), then \(\)ais trivially the root of the polynomial \(x-a\). But it also includes a lot of irrational numbers, like \(\sqrt{2}\) which is the root of \(x^2-2\). It also includes the imaginary unit \(i\), which is the solution of \(x^2+1\). If you’re not familiar with \(i\), take a look at the <a href="https://en.wikipedia.org/wiki/Complex_number">complex numbers</a>. They may seem a bit weird at first glance, but actually make things easier in a lot of cases.</p><p>The algebraic numbers do not contain \(\pi\) and \(e\), though.Proving that isn’t easy. The famous problem of squaring the circle asks whether \(\pi\) is in a certain subset of the algebraic numbers.It was posed by ancient Greek mathematicians and was solved only in 1882 by Lindemann who showed that \(\pi\) is not algebraic.Still, it is unproven that \(\pi + e\) is not algebraic, although pretty much everyone thinks so.There are a lot of similar examples, and a positive resolution to Schanuel’s conjecture would settle all of them.</p><p>We define the <strong>closed form numbers</strong> \(\mathbb{E}\) as those you get when you start with rational numbers and are allowed to apply addition, subtraction, multiplication, division and application of \(\exp\) or \(\log\) arbitrarily often. Take a look at Chow’s paper if you want to have this definition more formal.The closed form numbers include all algebraic numbers expressible as radicals:\[\sqrt[n]{a}=a^{\frac{1}{n}}=e^{\log(a) \cdot \frac{1}{n}}=\exp\left(\frac{\log(a)}{n}\right)\]They also include \(i=\sqrt{-1}\), as well as \(e = \exp(1)\) and \(\pi = -i\log(-1)\).Generally, the closed form numbers according to this definition capture pretty much every values you can compute without resorting to numerical approximation methods like <a href="https://en.wikipedia.org/wiki/Newton%27s_method">Newton’s method</a>.I’ll give a few more examples in case you’re not yet convinced of this:If \(x\) is a closed form number, then \(\sin(x)\) is also a closed form number:\[\sin(x) = \frac{\exp(ix) - \exp(-ix)}{2i}\]Similarly, we get:\[\tanh(x) = \frac{\exp(x)-\exp(-x)}{\exp(x)+\exp(-x)}\]and:\[\text{acos}(x) = -i \log\left(x+\exp\left(\frac{\log(x^2-1)}{2}\right)\right)\]</p><p>We call such functions, that map closed form numbers to closed form numbers by only using allowed operations <strong>closed form functions</strong>.</p><p>Not all numbers in \(\overline{\mathbb{Q}}\) can be expressed in closed form. The 5 roots of \(2x^5-10x+5\) are algebraic by definition, but can be shown using Galois theory to not be expressible by radicals. Chow showed that they can’t be expressed in closed form conditional on Schanuel’s conjecture. Khovanskii was later able to show this unconditionally.</p><p>Lastly, the definition of <strong>elementary numbers</strong> \(\mathbb{L}\) is similar to the definition of closed form numbers, but we are now also allowed to get the roots of polynomials. \(\mathbb{L}\) clearly contains all algebraic numbers as well as all closed form numbers.</p><figure class="mid"><img src="https://ninjakoa.la/curly_curves/elementary_numbers_venn_diagram.svg" alt="An overview over the numbers we defined"><figcaption> <p>An overview over the numbers we defined</p> </figcaption></figure><p>We now have everything in place to state Lin’s result.</p><h3 id="lins-theorem">Lin’s theorem</h3><p>If Schanuel’s conjecture is true and \(F(x,y) \in \overline{\mathbb{Q}}[x,y]\) is an irreducible polynomial involving both \(x\) and \(y\) and \(f(\alpha, e^\alpha) = 0\) for some \(\alpha \in \mathbb{C}\), then either \(\alpha = 0\) or \(\alpha \notin \mathbb{L}\).</p><p>Let’s give an example: Let \(F(x,y) = x+y\). Then \(F(x,y) \in \mathbb{Q}\) is irreducible and contains both \(x\) and \(y\).Thus, if \(\alpha\) satisfies \[F(\alpha,\exp(\alpha))=\alpha+\exp(\alpha)=0,\] then \(\alpha\) is not an elementary number.Hereby, you can prove that \(f(x)=x+\exp(x)\) has no closed form inverse:Suppose \(f^{-1}\) was a closed form function, then \(\alpha = f^{-1}(0)\) would be a closed form number, contradicting Lin’s theorem.</p><p>We can reformulate Lin’s result slightly by noting that \(\alpha\) is elementary if and only if \(\log(\alpha)\) is elementary:Just substitute \(\alpha\) with \(\log(\alpha)\) and switch \(x\) and \(y\).</p><h3 id="variant-of-lins-theorem">Variant of Lin’s theorem</h3><p>If Schanuel’s conjecture is true and \(F(x,y) \in \overline{\mathbb{Q}}[x,y]\) is an irreducible polynomial involving both \(x\) and \(y\) and \(f(\alpha, \log(\alpha)) = 0\) for some \(\alpha \in \mathbb{C}\), then either \(\alpha = 1\) or \(\alpha \notin \mathbb{L}\).</p><p>I hope I haven’t lost you yet :D</p><p>So how does any of this apply to quadratic Bézier curves?Let’s start by stating what we would like to have if it was possible:</p><p>We want to have a closed form formula, that given the control points of any quadratic Bézier curve and any parameter \(s\), computes a point on the curve that is exactly an arc length \(s\) apart from the starting point. I will show this to be impossible, by giving a single curve and parameter \(s\) such that it’s impossible. I didn’t need to try a lot of curves to find one where the proof works, I just took a curve which makes the involved mathematical expressions small.</p><h1 id="the-proof">The proof</h1><figure class="mid"><img src="https://ninjakoa.la/curly_curves/quadratic_bezier.svg" alt="Our quadratic Bézier curve"><figcaption> <p>Our quadratic Bézier curve</p> </figcaption></figure><p>I’m taking the control points to be\[p_0=\begin{pmatrix}0\\0\end{pmatrix}, \,p_1=\begin{pmatrix}\frac{1}{2}\\0\end{pmatrix}, \,p_1=\begin{pmatrix}1\\ \frac{1}{2}\end{pmatrix}\]Which leads to the \(x\) and \(y\) coordinates of the curve points at parameter \(t\) being:\[\begin{aligned}x(t) &= t \\y(t) &= \frac{t^2}{2}\end{aligned}\]The arc length of the curve is given by the integral over the length of the tangent:\[\begin{aligned}f(t) &= \int_0^t \sqrt{x’(s)^2+y’(s)^2} \: \mathrm{d}s \\&= \int_0^t \sqrt{s^2+1} \: \mathrm{d}s \\&= \frac{1}{2} \left(\, t \cdot \sqrt{t^{2} + 1} + \operatorname{arsinh}\left(t\right)\right) \\&= \frac{1}{2} \left(\, t \cdot \sqrt{t^{2} + 1} + \log\left(t + \sqrt{t^2+1}\right)\right)\end{aligned}\]</p><p>We now want to get rid of the expression inside the logarithm, in order to be able to apply Lin’s theorem.We define \(\varphi(t) = t + \sqrt{t^2+1}\) and get the inverse \(\varphi^{-1}(t) = \frac{t^2-1}{2t}\).By substituting \(t\) with \(\varphi^{-1}(x)\) and multiplying with \(2\) we get:\[2 \cdot f(\varphi^{-1}(x)) = \frac{x^4-1}{2x} + \log(x)\]We multiply with \(2x\) to get:\[4x \cdot f(\varphi^{-1}(x)) = x^4 + 2x \cdot \log(x) -1\]</p><p>We are now in the situation where we can apply Lin’s result: Define \(F(x,y) = x^4+2xy -1 \in \overline{\mathbb{Q}}[x,y]\).For checking the irreducibility, I just use <a href="https://www.sagemath.org/">sage</a>:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sage" data-lang="sage"><span style="display:flex;"><span>sage: R<span style="color:#f92672">.<</span>x,y<span style="color:#f92672">></span> <span style="color:#f92672">=</span> QQbar[]</span></span><span style="display:flex;"><span>sage: factor(x<span style="color:#f92672">^</span><span style="color:#ae81ff">4</span><span style="color:#f92672">+</span><span style="color:#ae81ff">2</span><span style="color:#f92672">*</span>x<span style="color:#f92672">*</span>y<span style="color:#f92672">+</span><span style="color:#ae81ff">1</span>)</span></span><span style="display:flex;"><span>x<span style="color:#f92672">^</span><span style="color:#ae81ff">4</span> <span style="color:#f92672">+</span> <span style="color:#ae81ff">2</span><span style="color:#f92672">*</span>x<span style="color:#f92672">*</span>y <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span></span></span></code></pre></div><p>Since \(F\) is irreducible, we get that any \(\alpha\) with \(F(\alpha, \log(\alpha))\) is \(1\) or nonelementary. Let’s check if it could be 1:\[1^4+2\cdot 1 \cdot \log(1) - 1 = 1 + 2 \cdot 0 - 1 = 0\]OK, shit. This is not going as planned. I wanted to show that the solution is nonelementary, but it turns out to just be 1.Let’s try to fix that. How about another substitution? If we substitute \(x\) with \(2x\), we get:\[\begin{aligned}8x \cdot f(\varphi^{-1}(2x)) &= 16x^4 + 4x \cdot \log(2x) - 1 \\\iff 8x \cdot f(\varphi^{-1}(2x)) &= 16x^4 + 4x \cdot \log(x)+4x \log(2) - 1 \\\iff 8x \cdot f(\varphi^{-1}(2x)) - 4x \log(2)&= 16x^4 + 4x \cdot \log(x) - 1\end{aligned}\]Now define \(G(x,y) = 16x^4+4xy-1\). This is irreducible as well. Let’s check for the special case of \(\alpha = 1\) again.\[16 \cdot 1^4+4\cdot 1 \cdot \log(1) - 1 = 16 + 2 \cdot 0 - 1 = 15\]Nice, \(1\) is no solution this time. So let \(\alpha\) be a number such that \[G(\alpha,\log(\alpha))=16\alpha^4 + 4x \cdot \log(\alpha) - 1=0.\]Then, by our variant of Lin’s Theorem, \(\alpha \notin \mathbb{L}\). Therefore, \(\alpha \notin \mathbb{E}\).</p><p>Since \(G(\alpha, \log(\alpha))=0\), by the above equation we get:\[\begin{aligned}8\alpha \cdot f(\varphi^{-1}(2\alpha)) - 4\alpha \log(2) &= 0 \\\iff 8\alpha \cdot f(\varphi^{-1}(2\alpha)) &= 4\alpha \log(2) \\\iff 2\alpha \cdot f(\varphi^{-1}(2\alpha)) &= \alpha \log(2)\end{aligned}\]Clearly \(\alpha \neq 0\) since \(\alpha \notin \mathbb{E}\), so we can divide by \(\alpha\):\[\begin{aligned}2 \cdot f(\varphi^{-1}(2\alpha)) &= \log(2) \\f(\varphi^{-1}(2\alpha)) &= \frac{\log(2)}{2} \\\varphi^{-1}(2\alpha) &= f^{-1}\left(\frac{\log(2)}{2}\right) \\2\alpha &= \varphi\left(f^{-1}\left(\frac{\log(2)}{2}\right)\right) \\\alpha &= \frac{\varphi\left(f^{-1}\left(\frac{\log(2)}{2}\right)\right)}{2} \\\end{aligned}\]</p><p>Since \(\varphi\) is a closed form function, if \(f^{-1}\) was a closed form function,\(\alpha\) would be a closed form number. But this is a contradiction to the fact that \(\alpha\) is not a closed form number by Lin’s theorem and the assumption that Schanuel’s conjecture is true.Therefore, \(f^{-1}\) is not a closed form function, which is what we wanted to show.</p><p>Of course, we can compute \(f^{-1}\) and \(\alpha\) numerically, for example using Newton’s method.So, if you’re curious, we get: \(\alpha \approx 0.609440243339721\).</p><h3 id="references">References</h3><p><a href="https://www.jstor.org/stable/43836165">Ferng-Chin Lin 1983: Schanuel’s conjecture implies Ritt’s conjectures</a><a href="http://timothychow.net/closedform.pdf">Timothy Chow 1999: What is a closed form number</a></p>