9 ms·
Whenever I dabble in type design or vector graphics I'm cursing Bézier curves. I do understand them rationally. But I just can't move the control points such th
by Tomte 11y ago
Whenever I dabble in type design or vector graphics I'm cursing Bézier curves. I do understand them rationally. But I just can't move the control points such that the result is what I want.
It's a pity that Knuth's Metafont curve definition system (with on-curve points) hasn't gotten more attention.
Or Karow's Ikarus software also had something with on-curve points, IIRC.
- jacobolus 11y agoLook up Raph Levien’s Ph.D thesis about “spiro” curves (a.k.a. cornu or Euler spirals). He not only proposes a pretty neat type of curve to use, which affords some nice UIs, but also does a great job detailing the history of splines, including other types of smooth “minimum energy” curves, IKARUS splines, Hobby splines (used by METAFONT), etc. http://www.levien.com/phd/phd.html http://www.levien.com/phd/phd.html [I’m somewhat surprised that the Pomax page doesn’t have a section about Hobby splines to go with the section about Catmull-Rom splines. Here’s the Stanford tech report describing them http://i.stanford.edu/pub/cstr/reports/cs/tr/85/1047/CS-TR-85-1047.pdf http://i.stanford.edu/pub/cstr/reports/cs/tr/85/1047/CS-TR-8... ; Apple’s Pages and Keynote programs now can use Hobby splines for making shapes, https://bosker.wordpress.com/2013/11/13/beyond-bezier-curves/ https://bosker.wordpress.com/2013/11/13/beyond-bezier-curves... ; the problem I have with Hobby splines is that there are certain types of shapes that are a real pain to create. As long as you want something very smooth it works pretty well, but whenever the Hobby curve isn’t giving you quite the result you want, tweaking it precisely can become really tricky, and you wish you just had full control over the Bézier arms. It could just be that I don’t have enough practice with them though.] Another type of curve that is very interesting for some applications is a Pythagorean-hodograph curve. These are curves such that the derivative in the X and Y direction are represented by "Pythagorean" polynomials, i.e. the hypotenuse √(x²+y²) is itself a polynomial. This means that the arclength can be precisely computed in closed form, as can mathematically precise offset curves, which makes them great for defining CAM cut paths. Lots of CAD software uses b-splines, specifically “NURBS”, as the main curve primitive. Some computer animation software uses subdivision surfaces instead. I’ve never been the biggest fan of UIs for manipulating either one. YMMV. Personally, I think even for using parametric cubic polynomial segments (i.e. for interoperating 1:1 with systems where the main drawing primitive is a cubic Bézier curve), it works a bit better from a UI perspective to specify the (x, y) locations of on-curve points at t = {0.0, 0.25, 0.75, 1.0} in each segment [these points are the extrema of the Chebyshev polynomial of the appropriate degree] and then convert to Bézier basis by multiplying by the appropriate matrix. I haven’t ever seen anyone try to implement such a UI in production software though, only my own little experimental doodles. (Only downside is that makes it slightly trickier to ensure smoothness at the endpoints in cases where that matters. I think this can be worked around with some extra UI effort.)
- Freak_NL 11y agoFree software vector drawing application Inkscape supports these spiro curves in its UI. It is an option you can select for the curves and lines drawing tool.
- jacobolus 11y agoYeah. Unfortunately I found Inkscape’s support for them kinda hacky and buggy: it’s clearly a bolted-on afterthought rather than a core part of the design. It also doesn’t support the full set of UI ideas from Levien’s thesis. But even so, it’s certainly a nice feature to have. Even with some interaction glitches, it’s still in many cases nicer to use than Bézier curves.
- taejo 11y agoFontForge's support for them is better in this regard, IMO.
- delhanty 11y agoRaph's thesis is a great piece of work. Having said that, it's worth making clear that the use of Euler Spirals in CAD predates his work. (His thesis is clear about this point.) In highway design they are known as clothoids. https://en.wikipedia.org/wiki/Track_transition_curve https://en.wikipedia.org/wiki/Track_transition_curve I worked as a consultant on a Japanese road design system (Sanei's STRAX Road CAD - still being sold it looks), and clothoids were already well established when I started in 1995.
- TheRealPomax 11y agoMy coffee table book "The Physics Book", by Clifford A. Pickover, dates practical applications of the clothoid curve back to at least 1901, when an engineer by the name of Edwin C. Prescott received a patent for their use in rollercoaster designs (after discovering the acceleration problems associated with circular loops some 1~2 years prior).
- starky 11y agoThis is understandable, since each control point affects the curve globally it is very difficult to get all the points in the correct position at once, particularly when the curve becomes higher order. Using NURBS is much more intuitive as using a particular knot will allow for specific local control.
- jacobolus 11y agoIn a piecewise Bézier curve, as used in vector graphics tools like Adobe Illustrator or Inkscape, or as the main curve primitive in PostScript, PDF, SVG, font formats, etc., each control point affects only a particular segment. Every shape tends to be made of numerous tiny segments.
- delhanty 11y agoNURBS curve can always be converted to piecewise Bézier by repeated knot-insertion. Having said that I too prefer spirals. Designing with piecewise Bézier curves is just a bad idea. Piecewise Bézier is a fine representation format once the curve is immutably defined. Bézier curves and surfaces, and the Bernstein Polynomial basis have "excellent numerical stability properties" http://mae.engr.ucdavis.edu/~farouki/bernstein.pdf http://mae.engr.ucdavis.edu/~farouki/bernstein.pdf which is just what you need for downstream processing. For example, intersection algorithms in CAD systems. Edit: I just realised that we are talking about polynomial Bézier curves here (rather than rational Bézier), so what I suggested for converting from NURBS to piecewise Bézier isn't going to work in general.
- jacobolus 11y agoFarouki’s paper is nice, but the advantages of the Bernstein basis are oversold IMO. In my opinion Chebyshev basis would be a better core representation for nearly every purpose (including rendering efficiency, degree raising / lowering, intersections, computing approximate arclengths, approximation of arbitrary parametric curves, etc.). I’ve been meaning to email Pomax about this for a while, but it’s going to take a somewhat long and involved email, so I keep putting it off.
- exDM69 11y ago> But I just can't move the control points such that the result is what I want. What you probably want is something like Kochanek-Bartels spline [0], which has on-the-curve control points with some extra parameters (tension, continuity, bias) and it gets broken down to Bezier segments. [0] https://en.wikipedia.org/wiki/Kochanek–Bartels_spline https://en.wikipedia.org/wiki/Kochanek–Bartels_spline
- amelius 11y agoI'm confused. The splines used in e.g. Inkscape (and Adobe Illustrator) are Bezier splines, right? And they allow local control of direction, with control-points on the spline. Are these also the splines used by SVG? What exactly is different in the splines of metafont?
- jacobolus 11y agoMetafont uses Hobby splines. Here’s the paper: http://i.stanford.edu/pub/cstr/reports/cs/tr/85/1047/CS-TR-85-1047.pdf http://i.stanford.edu/pub/cstr/reports/cs/tr/85/1047/CS-TR-8...
- Freak_NL 11y agoYes, in Inkscape the SVG backing what you see in the UI uses Bézier curves. A curving line drawn in Inkscape is an SVG path: https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Pa... In Inkscape you can open the XML Editor (from the Edit menu) and see how the object you've drawn is represented in SVG. A simple path with one Bézier curve may look like this: d: m 10,20 c 5,-5 15,10 20,5
- coffeeaddicted 11y agoSadly a lot of tools make it harder to work with beziers than necessary. Recently I checked half a dozen open source tools - and only a single one allowed locking the tangents at the points connecting 2 bezier curves. That is trivial to code as you just have to ensure the connecting point and the 2 control points before and behind it form a straight line. And without that using beziers is so much harder because that is the only way to have a smooth curve when connecting bezier-segments and fixing that manually is rather annoying.