How to know form of plotted Bézier function - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-10-17T04:18:51Z https://mathematica.stackexchange.com/feeds/question/29633 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/29633 2 How to know form of plotted Bézier function Pipe https://mathematica.stackexchange.com/users/1209 2013-08-01T12:55:32Z 2015-07-24T12:53:58Z <p>Simple scenario is to see the Bézier function, but how to know which polynomial approximate it?</p> <pre><code>pts = {{0, -1}, {1, 0}, {2, -1}}; Graphics[{BezierCurve[pts], Green, Line[pts], Red, Point[pts]}] </code></pre> https://mathematica.stackexchange.com/questions/29633/how-to-know-form-of-plotted-b%c3%a9zier-function/29659#29659 9 Answer by Michael E2 for How to know form of plotted Bézier function Michael E2 https://mathematica.stackexchange.com/users/4999 2013-08-01T18:38:23Z 2015-07-24T12:48:03Z <p><a href="http://mathworld.wolfram.com/BezierCurve.html" rel="noreferrer">Bézier Curves</a> have a standard formula:</p> <pre><code>bezier[pts_List] := With[{n = Length[pts] - 1}, Evaluate @ Sum[Binomial[n, i] (1 - #)^(n - i) #^i pts[[i + 1]], {i, 0, n}] &amp;] </code></pre> <p>In <em>Mathematica</em>, the coefficient function of <code>pts[[i + 1]]</code> is the same as <code>BernsteinBasis[n, i, #]</code>.</p> <p>The above formula is of degree one less than the number of points in <code>pts</code>. In the <em>Mathematica</em> function, the degree used in <code>BezierCurve</code> is typically limited to be at most the setting of <code>SplineDegree</code>. By default, the setting is <code>Automatic</code>, and experimentation shows that it is the same as <code>SplineDegree -&gt; 3</code>. In this case the list of points are partitioned into overlapping groups of 4 (or less).</p> <p><em>Example.</em> I added some more points, to show what happens when there is not a multiple of 4.</p> <pre><code>pts = {{0, -1}, {1, 0}, {2, -1}, {1, -1}, {2, 1}}; g1 = Graphics[{Green, Line[pts], Black, BezierCurve[pts], Red, Point[pts]}, Frame -&gt; True]; g2 = ParametricPlot[ Evaluate[bezier[#][t] &amp; /@ Partition[pts, 4, 3, 1, {}]], {t, 0, 1}, AspectRatio -&gt; Automatic, Frame -&gt; True, Axes -&gt; False, Prolog -&gt; {Green, Line[pts], Red, Point[pts]}]; GraphicsRow[{g1, g2}] bezier[#][t] &amp; /@ Partition[pts, 4, 3, 1, {}] </code></pre> <p><img src="https://i.stack.imgur.com/AhPUI.png" alt="Mathematica graphics"></p> <pre><code>(* {{3 (1 - t)^2 t + 6 (1 - t) t^2 + t^3, -(1 - t)^3 - 3 (1 - t) t^2 - t^3}, {1 + t, -1 + 2 t}} *) </code></pre> https://mathematica.stackexchange.com/questions/29633/how-to-know-form-of-plotted-b%c3%a9zier-function/29661#29661 0 Answer by george2079 for How to know form of plotted Bézier function george2079 https://mathematica.stackexchange.com/users/2079 2013-08-01T18:39:14Z 2013-08-01T18:39:14Z <p>In this particular case since you supplied three points you get a quadratic bezier:</p> <pre><code>t^2 pts[] + 2 t (1 - t) pts[] + (1 - t)^2 pts[] </code></pre> <p>You can see that this is correct at least to machine precision:</p> <pre><code>With[{t = RandomReal[{0, 1}]}, t^2 pts[] + 2 t (1 - t) pts[] + (1 - t)^2 pts[] == BezierFunction[pts][t]] </code></pre> <p>(* true *)</p> <p>Assuming that BezierCurve is based on BezierFunction of course..</p> <p>Of course the real question is how the divine this automatically, that I dont know..</p>