Composite Bézier curve: Difference between revisions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
 
imported>Lucasbrinster
 
Line 3: Line 3:
[[Image:Beziergon.svg|thumb|right|200px|Béziergon – The red béziergon passes through the blue vertices, the green points are control points that determine the shape of the connecting Bézier curves]]
[[Image:Beziergon.svg|thumb|right|200px|Béziergon – The red béziergon passes through the blue vertices, the green points are control points that determine the shape of the connecting Bézier curves]]
In [[geometric modelling]] and in [[computer graphics]], a '''composite Bézier curve''' or '''Bézier spline''' is a [[Spline (mathematics)|spline]] made out of [[Bézier curve]]s that is at least <math>C^0</math> [[continuous function|continuous]]. In other words, a composite Bézier curve is a series of Bézier curves joined end to end where the last point of one curve coincides with the starting point of the next curve. Depending on the application, additional smoothness requirements (such as <math>C^1</math> or <math>C^2</math> continuity) may be added.<ref name="ShikinPlis1995">{{cite book|author1=Eugene V. Shikin|author2=Alexander I. Plis|title=Handbook on Splines for the User|url=https://books.google.com/books?id=DL88KouJCQkC&pg=PA96|date=14 July 1995|publisher=CRC Press|isbn=978-0-8493-9404-1|page=96}}</ref>
In [[geometric modelling]] and in [[computer graphics]], a '''composite Bézier curve''' or '''Bézier spline''' is a [[Spline (mathematics)|spline]] made out of [[Bézier curve]]s that is at least <math>C^0</math> [[continuous function|continuous]]. In other words, a composite Bézier curve is a series of Bézier curves joined end to end where the last point of one curve coincides with the starting point of the next curve. Depending on the application, additional smoothness requirements (such as <math>C^1</math> or <math>C^2</math> continuity) may be added.<ref name="ShikinPlis1995">{{cite book|author1=Eugene V. Shikin|author2=Alexander I. Plis|title=Handbook on Splines for the User|url=https://books.google.com/books?id=DL88KouJCQkC&pg=PA96|date=14 July 1995|publisher=CRC Press|isbn=978-0-8493-9404-1|page=96}}</ref>
Perhaps the most common use of composite Béziers is to describe the outline of each letter in a [[PostScript]] or [[PDF]] file. Such outlines are composed of one béziergon for [[typeface anatomy|open letters]], or multiple béziergons for closed letters. Modern [[vector graphics]] and [[computer font]] systems like [[PostScript]], [[Asymptote (vector graphics language)|Asymptote]], [[Metafont]], [[OpenType]], and [[Scalable Vector Graphics|SVG]] use composite Bézier curves composed of cubic Bézier curves (3rd order curves) for drawing curved shapes.
==Terminology==
[[File:Sinc Function Approximation with Bezier Splines.svg|thumb|[[Sinc]] function approximated using a smooth Bézier spline, i.e., a series of smoothly-joined Bézier curves]]


A continuous composite Bézier is also called a '''polybézier''', by similarity to [[polyline]], but whereas in polylines the points are connected by straight lines, in a polybézier the points are connected by Bézier curves. A '''béziergon''' (also called '''bézigon''') is a closed path composed of [[Bézier curve]]s. It is similar to a [[polygon]] in that it connects a set of [[vertex (geometry)|vertices]] by lines, but whereas in polygons the vertices are connected by straight lines, in a béziergon the vertices are connected by Bézier curves.<ref>[http://msdn2.microsoft.com/en-us/library/ms534244.aspx Microsoft polybezier API]
A continuous composite Bézier is also called a '''polybézier''', by similarity to [[polyline]], but whereas in polylines the points are connected by straight lines, in a polybézier the points are connected by Bézier curves. A '''béziergon''' (also called '''bézigon''') is a closed path composed of [[Bézier curve]]s. It is similar to a [[polygon]] in that it connects a set of [[vertex (geometry)|vertices]] by lines, but whereas in polygons the vertices are connected by straight lines, in a béziergon the vertices are connected by Bézier curves.<ref>[http://msdn2.microsoft.com/en-us/library/ms534244.aspx Microsoft polybezier API]
</ref><ref>[http://libpapyrus.sourceforge.net/guide_beziergon.html Papyrus béziergon API reference]
</ref><ref>[https://libpapyrus.sourceforge.net/guide_beziergon.html Papyrus béziergon API reference]
</ref><ref>[https://books.google.com/books?id=nFAEAAAAMBAJ&dq=bezigon+curve&pg=PA85 "A better box of crayons"].
</ref><ref>[https://books.google.com/books?id=nFAEAAAAMBAJ&dq=bezigon+curve&pg=PA85 "A better box of crayons"].
InfoWorld.
InfoWorld.
1991.</ref> Some authors even call a <math>C^0</math> composite Bézier curve a "Bézier spline";<ref>{{Cite book|url=https://books.google.com/books?id=lFwXglfyoIQC|title=A First Course in Applied Mathematics|last=Rebaza|first=Jorge|date=2012-04-24|publisher=John Wiley & Sons|isbn=9781118277157|language=en}}</ref> the latter term is however used by other authors as a synonym for the (non-composite) Bézier curve, and they add "composite" in front of "Bézier spline" to denote the composite case.<ref>{{Cite book|url=https://books.google.com/books?id=VnH0UzTycTcC|title=Mathematica ® 3.0 Standard Add-on Packages|last=(Firm)|first=Wolfram Research|date=1996-09-13|publisher=Cambridge University Press|isbn=9780521585859|language=en}}</ref>
1991.</ref> Some authors even call a <math>C^0</math> composite Bézier curve a "Bézier spline";<ref>{{Cite book|url=https://books.google.com/books?id=lFwXglfyoIQC|title=A First Course in Applied Mathematics|last=Rebaza|first=Jorge|date=2012-04-24|publisher=John Wiley & Sons|isbn=9781118277157|language=en}}</ref> the latter term is however used by other authors as a synonym for the (non-composite) Bézier curve, and they add "composite" in front of "Bézier spline" to denote the composite case.<ref>{{Cite book|url=https://books.google.com/books?id=VnH0UzTycTcC|title=Mathematica ® 3.0 Standard Add-on Packages|last=(Firm)|first=Wolfram Research|date=1996-09-13|publisher=Cambridge University Press|isbn=9780521585859|language=en}}</ref>
Perhaps the most common use of composite Béziers is to describe the outline of each letter in a [[PostScript]] or [[PDF]] file. Such outlines are composed of one béziergon for [[typeface anatomy|open letters]], or multiple béziergons for closed letters. Modern [[vector graphics]] and [[computer font]] systems like [[PostScript]], [[Asymptote (vector graphics language)|Asymptote]], [[Metafont]], [[OpenType]], and [[Scalable Vector Graphics|SVG]] use composite Bézier curves composed of cubic Bézier curves (3rd order curves) for drawing curved shapes.
[[File:Sinc Function Approximation with Bezier Splines.svg|thumb|[[Sinc]] function approximated using a smooth Bézier spline, i.e., a series of smoothly-joined Bézier curves]]


==Smooth joining==
==Smooth joining==
Line 22: Line 23:
Given two cubic Bézier curves with control points <math>[\mathbf  P_0,\mathbf  P_1,\mathbf  P_2,\mathbf  P_3]</math> and <math>[\mathbf  P_3,\mathbf  P_4,\mathbf  P_5,\mathbf  P_6]</math> respectively, the constraints for ensuring continuity at <math>\mathbf  P_3</math> can be defined as follows:
Given two cubic Bézier curves with control points <math>[\mathbf  P_0,\mathbf  P_1,\mathbf  P_2,\mathbf  P_3]</math> and <math>[\mathbf  P_3,\mathbf  P_4,\mathbf  P_5,\mathbf  P_6]</math> respectively, the constraints for ensuring continuity at <math>\mathbf  P_3</math> can be defined as follows:


* <math>C^0/G^0</math> (positional continuity) requires that they meet at the same point, which all Bézier splines do by definition. In this example, the shared point is <math>\mathbf  P_3</math>
* <math>C^0/G^0</math> (positional continuity) requires that they meet at the same point, which all polybéziers do by definition. In this example, the shared point is <math>\mathbf  P_3</math>
 
* <math>C^1</math> (velocity continuity) requires the neighboring control points around the join to be mirrors of each other. In other words, they must follow the constraint of <math>\mathbf  P_4=2\mathbf  P_3-\mathbf  P_2</math>
* <math>C^1</math> (velocity continuity) requires the neighboring control points around the join to be mirrors of each other. In other words, they must follow the constraint of <math>\mathbf  P_4=2\mathbf  P_3-\mathbf  P_2</math>
* <math>G^1</math> (tangent continuity) requires the neighboring control points to be [[collinearity|collinear]] with the join. This is less strict than <math>C^1</math> continuity, leaving an extra degree of freedom which can be parameterized using a scalar <math>\beta_1</math>. The constraint can then be expressed by <math>\mathbf  P_4=\mathbf  P_3+(\mathbf  P_3-\mathbf  P_2)\beta_1</math>
* <math>G^1</math> (tangent continuity) requires the neighboring control points to be [[collinearity|collinear]] with the join. This is less strict than <math>C^1</math> continuity, leaving an extra degree of freedom which can be parameterized using a scalar <math>\beta_1</math>. The constraint can then be expressed by <math>\mathbf  P_4=\mathbf  P_3+(\mathbf  P_3-\mathbf  P_2)\beta_1</math>


While the following continuity constraints are possible, they are rarely used with cubic Bézier splines, as other splines like the [[B-spline]] or the [[Beta-spline|β-spline]]<ref>
While the following continuity constraints are possible, they are rarely used with cubic polybéziers, as other splines like the [[B-spline]] or the [[Beta-spline|β-spline]]<ref>
{{Cite journal|title=Properties of β-splines|last=Goodman|first=T.N.T|journal=Journal of Approximation Theory |language=en|date=1983-12-09|volume=44 |issue=2 |pages=132–153 |doi=10.1016/0021-9045(85)90076-0 |doi-access=free}}</ref> will naturally handle higher constraints without loss of local control.
{{Cite journal|title=Properties of β-splines|last=Goodman|first=T.N.T.|journal=Journal of Approximation Theory |language=en|date=1983-12-09|volume=44 |issue=2 |pages=132–153 |doi=10.1016/0021-9045(85)90076-0 |doi-access=free}}</ref> will naturally handle higher constraints without loss of local control.


* <math>C^2</math> (acceleration continuity) is constrained by <math>\mathbf  P_5 =\mathbf  P_1+4(\mathbf  P_3-\mathbf  P_2)</math>. However, applying this constraint across an entire cubic Bézier spline will cause a cascading loss of local control over the tangent points. The curve will still pass through every third point in the spline, but control over its shape will be lost. In order to achieve <math>C^2</math> continuity using cubic curves, it's recommended to use a cubic uniform B-spline instead, as it ensures <math>C^2</math> continuity without loss of local control, at the expense of no longer being guaranteed to pass through specific points
* <math>C^2</math> (acceleration continuity) is constrained by <math>\mathbf  P_5 =\mathbf  P_1+4(\mathbf  P_3-\mathbf  P_2)</math>. However, applying this constraint across an entire cubic Bézier spline will cause a cascading loss of local control over the tangent points. The curve will still pass through every third point in the spline, but control over its shape will be lost. In order to achieve <math>C^2</math> continuity using cubic curves, it's recommended to use a cubic uniform B-spline instead, as it ensures <math>C^2</math> continuity without loss of local control, at the expense of no longer being guaranteed to pass through specific points
* <math>G^2</math> (curvature continuity) is constrained by <math>\mathbf  P_5=\mathbf  P_3+(\mathbf  P_3-\mathbf  P_2)(2\beta_1+\beta_1^2+\beta_2/2)+(\mathbf  P_1-\mathbf  P_2)\beta_1^2</math>, leaving two degrees of freedom compared to <math>C^2</math>, in the form of two scalars <math>\beta_1</math> and <math>\beta_2</math>. Higher degrees of geometric continuity is possible, though they get increasingly complex<ref>
* <math>G^2</math> (curvature continuity) is constrained by <math>\mathbf  P_5=\mathbf  P_3+(\mathbf  P_3-\mathbf  P_2)(2\beta_1+\beta_1^2+\beta_2/2)+(\mathbf  P_1-\mathbf  P_2)\beta_1^2</math>, leaving two degrees of freedom compared to <math>C^2</math>, in the form of two scalars <math>\beta_1</math> and <math>\beta_2</math>. Higher degrees of geometric continuity is possible, though they get increasingly complex<ref>
{{Cite web|url=https://www2.eecs.berkeley.edu/Pubs/TechRpts/1986/6081.html|title=Geometric Continuity: A Parametrization Independent Measure of Continuity for Computer Aided Geometric Design|last=DeRose|first=Anthony D.|language=en|date=1985-08-01}}
{{Cite web|url=https://www2.eecs.berkeley.edu/Pubs/TechRpts/1986/6081.html|title=Geometric Continuity: A Parametrization Independent Measure of Continuity for Computer Aided Geometric Design|last=DeRose|first=Anthony D.|language=en|date=1985-08-01}}
</ref>
</ref>
* <math>C^3</math> (jolt continuity) is constrained by <math>\mathbf  P_6=\mathbf  P_3+(\mathbf  P_3-\mathbf  P_0)+6(\mathbf  P_1-\mathbf  P_2+\mathbf  P_3-\mathbf  P_2)</math>. Applying this constraint to the cubic Bézier spline will cause a complete loss of local control, as the entire spline is now fully constrained and defined by the first curve's control points. In fact, it is arguably no longer a spline, as its shape is now equivalent to extrapolating the first curve indefinitely, making it not only <math>C^3</math> continuous, but <math>C^\infin</math>, as joins between separate curves no longer exist
* <math>C^3</math> (jolt continuity) is constrained by <math>\mathbf  P_6=\mathbf  P_3+(\mathbf  P_3-\mathbf  P_0)+6(\mathbf  P_1-\mathbf  P_2+\mathbf  P_3-\mathbf  P_2)</math>. Applying this constraint to the cubic Bézier spline will cause a complete loss of local control, as the entire spline is now fully constrained and defined by the first curve's control points. In fact, it is arguably no longer a spline, as its shape is now equivalent to extrapolating the first curve indefinitely, making it not only <math>C^3</math> continuous, but <math>C^\infin</math>, as joins between separate curves no longer exist


==Approximating circular arcs==
==Approximating circular arcs==
In case circular arc primitives are not supported in a particular environment, they may be approximated by [[Bézier curve]]s.<ref>{{Cite web
In case [[circular arc]] primitives are not supported in a particular environment, they may be approximated by [[Bézier curve]]s.<ref name=Stanislav>{{Cite web
   | last = Stanislav
   | last = Stanislav
   | first = G. Adam
   | first = G. Adam
   | title = Drawing a circle with Bézier Curves
   | title = Drawing a circle with Bézier Curves
   | url=http://whizkidtech.redprince.net/bezier/circle/
   | url=http://whizkidtech.redprince.net/bezier/circle/
  | archive-url=http://web.archive.org/web/20230616034149/http://whizkidtech.redprince.net/bezier/circle/|archive-date=2023-06-16
   | accessdate = 10 April 2010 }}
   | accessdate = 10 April 2010 }}
</ref> Commonly, eight quadratic segments<ref>{{Cite web
</ref> Commonly, eight quadratic segments<ref>{{Cite web
Line 51: Line 49:
|url=https://developer.apple.com/fonts/ttrefman/RM01/Chap1.html
|url=https://developer.apple.com/fonts/ttrefman/RM01/Chap1.html
|accessdate=26 July 2014
|accessdate=26 July 2014
}}</ref> or four cubic segments are used to approximate a circle. It is desirable to find the length <math>\mathbf{k}</math> of control points which result in the least approximation error for a given number of cubic segments.
}}</ref> or four cubic segments are used to approximate a circle. It is desirable to find the length <math>\mathbf{k}</math> of control points which result in the least [[approximation error]] for a given number of cubic segments.


===Using four curves===
===Using four curves===
Line 73: Line 71:
:<math>
:<math>
\begin{align}
\begin{align}
\mathbf{C} &= \frac{1}{8}\mathbf{A} + \frac{3}{8}\mathbf{A'}+\frac{3}{8}\mathbf{B'}+\frac{1}{8}\mathbf{B} \\
\mathbf{C} &= \frac{1}{8}\mathbf{A} + \frac{3}{8}\mathbf{A'}+\frac{3}{8}\mathbf{B'}+\frac{1}{8}\mathbf{B} & \text{(by substitution into cubic Bézier definition)} \\
\mathbf{C} &= \sqrt{1/2} = \sqrt{2}/2
\mathbf{C} &= [\sqrt{2}/2, \sqrt{2}/2] & \text{(by the definition of a circle)}
\end{align}
\end{align}
</math>
</math>


Solving these equations for the x-coordinate (and identically for the y-coordinate) yields:
Solving these equations for the x-coordinate (and identically for the y-coordinate) yields:<ref name=Stanislav/>


:<math>\frac{0}{8}\mathbf + \frac{3}{8}\mathbf{k}+\frac{3}{8} + \frac{1}{8} = \sqrt{2}/2</math>
:<math>\frac{0}{8}\mathbf + \frac{3}{8}\mathbf{k}+\frac{3}{8} + \frac{1}{8} = \sqrt{2}/2</math>
:<math>\mathbf{k} = \frac{4}{3}(\sqrt{2} - 1) \approx 0.5522847498</math>
:<math>\mathbf{k} = \frac{4}{3}(\sqrt{2} - 1) \approx 0.5522847498</math>


Note however that the resulting Bézier curve is entirely outside the circle, with a maximum deviation of the radius of about 0.00027.
==== Error analysis ====
By adding a small correction to intermediate points such as  
Note however that the resulting Bézier curve is entirely outside the circle, with a maximum deviation of the radius of about 0.00027. For the rest of the discussion, the radial drift for a given {{math|''t''}} is <math>\sqrt{x(t)^2 + y(t)^2}-1</math>.
 
'''Unattributed correction:'''{{cn|date=August 2025}} Adding a small correction to intermediate points such as  


:<math>
:<math>
Line 94: Line 94:


the magnitude of the radius deviation to 1 is reduced by a factor of about 3, to 0.000068 (at the expense of the derivability of the approximated circle curve at endpoints).
the magnitude of the radius deviation to 1 is reduced by a factor of about 3, to 0.000068 (at the expense of the derivability of the approximated circle curve at endpoints).
'''Ellsworth's three-parameter correction:''' Instead of solving for a single ''k'', solve for <math>\mathbf{A} = [0, a],</math> <math>\mathbf{A'} = [b, c],</math> <math>\mathbf{B'} = [c, b],</math> <math>\mathbf{B} = [a, 0].</math> Minimize the maximum radial drift, which is <math display=inline>f(a,b,c) = \max(\left|d(t)\right|, 0 \leq t \leq 1)</math>. Solving numerically gives {{math|1=''a''&thinsp;=&thinsp;1.00005507808,}} {{math|1=''b''&thinsp;=&thinsp;0.55342925736,}} and {{math|1=''c''&thinsp;=&thinsp;0.99873327689}}. The maximum radial drift is 0.000055.<ref name=Mortensen>{{cite web |last1=Mortensen |first1=Spencer |title=Approximate a circle with cubic Bézier curves |url=https://spencermortensen.com/articles/bezier-circle/ |website=spencermortensen.com |date=2012}}</ref>
'''Ellsworth's least-square correction:''' Solve for the ''k'' that minimizes <math display=inline>\int_0^1 {\left(d(t)\right)}^2 dt</math>. Numerically <math>k \approx 0.55197038140</math>. The maximal radial drift is 0.0002, for a 1.9% reduction in the total squared radial drift compared to the three-parameter case.<ref>{{cite web |last1=Mortensen |first1=Spencer |title=Least-squares approximation of the circle using cubic Bézier curves |url=https://spencermortensen.com/articles/least-squares-bezier-circle/ |website=spencermortensen.com |date=2022}}</ref>


===General case===
===General case===
We may approximate a circle of radius <math>R</math> from an arbitrary number of cubic Bézier curves. Let the arc start at point <math>\mathbf{A}</math> and end at point <math>\mathbf{B}</math>, placed at equal distances above and below the x-axis, spanning an arc of angle <math>\theta = 2\phi</math>:
We may approximate a unit circle of radius from an arbitrary number of cubic Bézier curves. Let the arc start at point <math>\mathbf{A}</math> and end at point <math>\mathbf{B}</math>, placed at equal distances above and below the x-axis, spanning an arc of angle <math>\theta = 2\phi \leq = \tfrac{\pi}{2}</math>:


:<math>\begin{align}
:<math>\begin{align}
\mathbf{A}_x &= R\cos(\phi) \\
\mathbf{A} &= [\cos(\phi), \sin(\phi)]  \\
\mathbf{A}_y &= R\sin(\phi) \\
\mathbf{B} &= [\cos(\phi), -\sin(\phi)] = [\mathbf{A}_x, -\mathbf{A}_y]
\mathbf{B}_x &= \mathbf{A}_x \\
\mathbf{B}_y &= -\mathbf{A}_y
\end{align}</math>
\end{align}</math>


The control points may be written as:<ref>
After solving for the curve starting and ending at the given points, the arc's midpoint occurring at <math>t=0.5</math>, and the curve's end point tangents being the same as the circles, the control points may be written as:
 
:<math>\begin{align}
\mathbf{A'} &= [\frac{4 - \mathbf{A}_x}{3}, \frac{(1 - \mathbf{A}_x)(3 - \mathbf{A}_x)}{3\mathbf{A}_y}] &= [\frac{4 - \cos(\phi)}{3}, \frac{(1 - \cos(\phi))(3 - \cos(\phi))}{3\sin(\phi)}] \\
\mathbf{B'} &= [\mathbf{A'}_x, -\mathbf{A'}_y] &= [\frac{4 - \cos(\phi)}{3}, \frac{(1 - \cos(\phi))(3 - \cos(\phi))}{-3\sin(\phi)}]
\end{align}</math>
 
Multiplying the values provide general solutions for arcs of any radius. Using rotation matrices allows the drawing of any angle.<ref>
{{Cite web
{{Cite web
  | date = 2004
   | last = DeVeneza
   | last = DeVeneza
   | first = Richard
   | first = Richard
Line 113: Line 123:
   | accessdate = 10 April 2010 }}</ref>
   | accessdate = 10 April 2010 }}</ref>


:<math>\begin{align}
The constraints of Ellsworth's solutions can be applied to the general case and numerically solved as well.
\mathbf{A'}_x &= \frac{4R - \mathbf{A}_x}{3} \\
\mathbf{A'}_y &= \frac{(R - \mathbf{A}_x)(3R - \mathbf{A}_x)}{3\mathbf{A}_y} \\
\mathbf{B'}_x &= \mathbf{A'}_x \\
\mathbf{B'}_y &= -\mathbf{A'}_y
\end{align}</math>


===Examples===
===Examples===
Line 125: Line 130:
File:Circle and cubic bezier.svg|Four-segment cubic polybézier (red) approximating a circle (black) with control points
File:Circle and cubic bezier.svg|Four-segment cubic polybézier (red) approximating a circle (black) with control points
</gallery>
</gallery>
=== Other approaches ===
For Bézier curves of degree ''n'' > 1, Ahn (2019) provide an <math>G^2</math> approximation for any number of segments. The [[Hausdorff distance]] as well as the aforementioned "radial drift" show 2''n''-1 extreme points and Ahn's approximation is, as of the time of publication, the one with the smallest maximum Hausdorff distance. Explicit, analytical solutions are provided for the quadratic, cubic, and quartic cases.<ref>{{cite journal |last1=Ahn |first1=Young Joon |title=Circle approximation by G 2 Bézier curves of degree n with 2 n − 1 extreme points |journal=Journal of Computational and Applied Mathematics |date=October 2019 |volume=358 |pages=20–28 |doi=10.1016/j.cam.2019.02.037}}</ref>
Applying [[affine transformation]] to the constraints allows the drawing of ellipses and elliptical arcs.<ref>{{cite arXiv | last1=Van Aken | first1=Jerry R. | title=Drawing ellipses and elliptical arcs with piecewise cubic Bézier curve approximations | date=2024 | class=cs.GR | eprint=2407.17675 }}</ref>


==Fonts==
==Fonts==
[[TrueType]] fonts use composite Béziers composed of '''quadratic''' Bézier curves (2nd order curves). To describe a typical [[type design]] as a [[computer font]] to any given accuracy, 3rd order Béziers require less data than 2nd order Béziers; and these in turn require less data than a series of straight lines. This is true even though any one straight line segment requires less data than any one segment of a parabola; and that parabolic segment in turn requires less data than any one segment of a 3rd order curve.
[[TrueType]] fonts use composite Béziers composed of '''quadratic''' Bézier curves (2nd order curves) while most [[PostScript fonts#Technology|PostScript Type 1 and OpenType CFF]] use '''cubic''' (3rd order) curves. To describe a typical [[type design]] as a [[computer font]] to any given accuracy, 3rd order Béziers require less data than 2nd order Béziers; and these in turn require less data than a series of straight lines. This is true even though any one straight [[line segment]] requires less data than any one segment of a parabola; and that parabolic segment in turn requires less data than any one segment of a 3rd order curve.


==See also==
==See also==

Latest revision as of 22:18, 31 October 2025

Template:Short description Template:Use dmy dates

File:Beziergon.svg
Béziergon – The red béziergon passes through the blue vertices, the green points are control points that determine the shape of the connecting Bézier curves

In geometric modelling and in computer graphics, a composite Bézier curve or Bézier spline is a spline made out of Bézier curves that is at least C0 continuous. In other words, a composite Bézier curve is a series of Bézier curves joined end to end where the last point of one curve coincides with the starting point of the next curve. Depending on the application, additional smoothness requirements (such as C1 or C2 continuity) may be added.[1]

Perhaps the most common use of composite Béziers is to describe the outline of each letter in a PostScript or PDF file. Such outlines are composed of one béziergon for open letters, or multiple béziergons for closed letters. Modern vector graphics and computer font systems like PostScript, Asymptote, Metafont, OpenType, and SVG use composite Bézier curves composed of cubic Bézier curves (3rd order curves) for drawing curved shapes.

Terminology

File:Sinc Function Approximation with Bezier Splines.svg
Sinc function approximated using a smooth Bézier spline, i.e., a series of smoothly-joined Bézier curves

A continuous composite Bézier is also called a polybézier, by similarity to polyline, but whereas in polylines the points are connected by straight lines, in a polybézier the points are connected by Bézier curves. A béziergon (also called bézigon) is a closed path composed of Bézier curves. It is similar to a polygon in that it connects a set of vertices by lines, but whereas in polygons the vertices are connected by straight lines, in a béziergon the vertices are connected by Bézier curves.[2][3][4] Some authors even call a C0 composite Bézier curve a "Bézier spline";[5] the latter term is however used by other authors as a synonym for the (non-composite) Bézier curve, and they add "composite" in front of "Bézier spline" to denote the composite case.[6]

Smooth joining

A commonly desired property of splines is for them to join their individual curves together with a specified level of parametric or geometric continuity. While individual curves in the spline are fully C continuous within their own interval, there is always some amount of discontinuity where different curves meet.

The Bézier spline is fairly unique in that it's one of the few splines that doesn't guarantee any higher degree of continuity than C0. It is, however, possible to arrange control points to guarantee various levels of continuity across joins, though this can come at a loss of local control if the constraint is too strict for the given degree of the Bézier spline.

Smoothly joining cubic Béziers

Given two cubic Bézier curves with control points [𝐏0,𝐏1,𝐏2,𝐏3] and [𝐏3,𝐏4,𝐏5,𝐏6] respectively, the constraints for ensuring continuity at 𝐏3 can be defined as follows:

  • C0/G0 (positional continuity) requires that they meet at the same point, which all polybéziers do by definition. In this example, the shared point is 𝐏3
  • C1 (velocity continuity) requires the neighboring control points around the join to be mirrors of each other. In other words, they must follow the constraint of 𝐏4=2𝐏3𝐏2
  • G1 (tangent continuity) requires the neighboring control points to be collinear with the join. This is less strict than C1 continuity, leaving an extra degree of freedom which can be parameterized using a scalar β1. The constraint can then be expressed by 𝐏4=𝐏3+(𝐏3𝐏2)β1

While the following continuity constraints are possible, they are rarely used with cubic polybéziers, as other splines like the B-spline or the β-spline[7] will naturally handle higher constraints without loss of local control.

  • C2 (acceleration continuity) is constrained by 𝐏5=𝐏1+4(𝐏3𝐏2). However, applying this constraint across an entire cubic Bézier spline will cause a cascading loss of local control over the tangent points. The curve will still pass through every third point in the spline, but control over its shape will be lost. In order to achieve C2 continuity using cubic curves, it's recommended to use a cubic uniform B-spline instead, as it ensures C2 continuity without loss of local control, at the expense of no longer being guaranteed to pass through specific points
  • G2 (curvature continuity) is constrained by 𝐏5=𝐏3+(𝐏3𝐏2)(2β1+β12+β2/2)+(𝐏1𝐏2)β12, leaving two degrees of freedom compared to C2, in the form of two scalars β1 and β2. Higher degrees of geometric continuity is possible, though they get increasingly complex[8]
  • C3 (jolt continuity) is constrained by 𝐏6=𝐏3+(𝐏3𝐏0)+6(𝐏1𝐏2+𝐏3𝐏2). Applying this constraint to the cubic Bézier spline will cause a complete loss of local control, as the entire spline is now fully constrained and defined by the first curve's control points. In fact, it is arguably no longer a spline, as its shape is now equivalent to extrapolating the first curve indefinitely, making it not only C3 continuous, but C, as joins between separate curves no longer exist

Approximating circular arcs

In case circular arc primitives are not supported in a particular environment, they may be approximated by Bézier curves.[9] Commonly, eight quadratic segments[10] or four cubic segments are used to approximate a circle. It is desirable to find the length 𝐤 of control points which result in the least approximation error for a given number of cubic segments.

Using four curves

Considering only the 90-degree unit-circular arc in the first quadrant, we define the endpoints 𝐀 and 𝐁 with control points 𝐀 and 𝐁, respectively, as:

𝐀=[0,1]𝐀=[𝐤,1]𝐁=[1,𝐤]𝐁=[1,0]

From the definition of the cubic Bézier curve, we have:

𝐂(t)=(1t)3𝐀+3(1t)2t𝐀+3(1t)t2𝐁+t3𝐁

With the point 𝐂(t=0.5) as the midpoint of the arc, we may write the following two equations:

𝐂=18𝐀+38𝐀+38𝐁+18𝐁(by substitution into cubic Bézier definition)𝐂=[2/2,2/2](by the definition of a circle)

Solving these equations for the x-coordinate (and identically for the y-coordinate) yields:[9]

08+38𝐤+38+18=2/2
𝐤=43(21)0.5522847498

Error analysis

Note however that the resulting Bézier curve is entirely outside the circle, with a maximum deviation of the radius of about 0.00027. For the rest of the discussion, the radial drift for a given Template:Math is x(t)2+y(t)21.

Unattributed correction:Script error: No such module "Unsubst". Adding a small correction to intermediate points such as

𝐀=[𝐤+0.0009,10.00103]𝐁=[10.00103,𝐤+0.0009],

the magnitude of the radius deviation to 1 is reduced by a factor of about 3, to 0.000068 (at the expense of the derivability of the approximated circle curve at endpoints).

Ellsworth's three-parameter correction: Instead of solving for a single k, solve for 𝐀=[0,a], 𝐀=[b,c], 𝐁=[c,b], 𝐁=[a,0]. Minimize the maximum radial drift, which is f(a,b,c)=max(|d(t)|,0t1). Solving numerically gives Template:Math Template:Math and Template:Math. The maximum radial drift is 0.000055.[11]

Ellsworth's least-square correction: Solve for the k that minimizes 01(d(t))2dt. Numerically k0.55197038140. The maximal radial drift is 0.0002, for a 1.9% reduction in the total squared radial drift compared to the three-parameter case.[12]

General case

We may approximate a unit circle of radius from an arbitrary number of cubic Bézier curves. Let the arc start at point 𝐀 and end at point 𝐁, placed at equal distances above and below the x-axis, spanning an arc of angle θ=2ϕ=π2:

𝐀=[cos(ϕ),sin(ϕ)]𝐁=[cos(ϕ),sin(ϕ)]=[𝐀x,𝐀y]

After solving for the curve starting and ending at the given points, the arc's midpoint occurring at t=0.5, and the curve's end point tangents being the same as the circles, the control points may be written as:

𝐀=[4𝐀x3,(1𝐀x)(3𝐀x)3𝐀y]=[4cos(ϕ)3,(1cos(ϕ))(3cos(ϕ))3sin(ϕ)]𝐁=[𝐀x,𝐀y]=[4cos(ϕ)3,(1cos(ϕ))(3cos(ϕ))3sin(ϕ)]

Multiplying the values provide general solutions for arcs of any radius. Using rotation matrices allows the drawing of any angle.[13]

The constraints of Ellsworth's solutions can be applied to the general case and numerically solved as well.

Examples

Other approaches

For Bézier curves of degree n > 1, Ahn (2019) provide an G2 approximation for any number of segments. The Hausdorff distance as well as the aforementioned "radial drift" show 2n-1 extreme points and Ahn's approximation is, as of the time of publication, the one with the smallest maximum Hausdorff distance. Explicit, analytical solutions are provided for the quadratic, cubic, and quartic cases.[14]

Applying affine transformation to the constraints allows the drawing of ellipses and elliptical arcs.[15]

Fonts

TrueType fonts use composite Béziers composed of quadratic Bézier curves (2nd order curves) while most PostScript Type 1 and OpenType CFF use cubic (3rd order) curves. To describe a typical type design as a computer font to any given accuracy, 3rd order Béziers require less data than 2nd order Béziers; and these in turn require less data than a series of straight lines. This is true even though any one straight line segment requires less data than any one segment of a parabola; and that parabolic segment in turn requires less data than any one segment of a 3rd order curve.

See also

References

Template:Reflist

  1. Script error: No such module "citation/CS1".
  2. Microsoft polybezier API
  3. Papyrus béziergon API reference
  4. "A better box of crayons". InfoWorld. 1991.
  5. Script error: No such module "citation/CS1".
  6. Script error: No such module "citation/CS1".
  7. Script error: No such module "Citation/CS1".
  8. Script error: No such module "citation/CS1".
  9. a b Script error: No such module "citation/CS1".
  10. Script error: No such module "citation/CS1".
  11. Script error: No such module "citation/CS1".
  12. Script error: No such module "citation/CS1".
  13. Script error: No such module "citation/CS1".
  14. Script error: No such module "Citation/CS1".
  15. Script error: No such module "citation/CS1".