Is it possible to draw Bezier curves without using line segments?

Started by
12 comments, last by Zlodo 11 years, 5 months ago
When I started programming at age eight on a 68000-based Mac, I was fascinated by QuickDraw's ability to draw geometric shapes so quickly. This led to years of searching as to how (I started well before the internet was established). I now have an admittedly pointless, but interesting cache of pixel-perfect (midpoint) geometric object drawing code (ellipses, elliptical arcs, lines, etc.). This kind of became a hobby of mine.

One thing that I have noticed is that I have never seen a similar method for drawing Bezier curves. I have seen countless algorithms for drawing them, but they all rely on calculating the end points for line segments and then drawing the line segments. Searching for "midpoint Bezier algorithm" returns vast amounts of results for Bezier subdivision, but nothing about drawing curves pixel by pixel.

I am just curious if anyone here has ever seen or heard of such an algorithm. Sadly, the math is a little beyond my abilities, so rolling my own is out. It just seems like this should be possible. If this cannot be done, what is the reason?
Advertisement
You can solve a Bezier curve at any location. Drawing it as a series of line segments provides an approximation of the curve, with the tradeoff being between drawing time and resolution. If you reduce your step between endpoints to a small enough increment you end up with pixel-sized segments in between endpoints, at the cost of having to draw more tiny little line segments, but at this level it becomes as close to "pixel perfect" as you can get. So there is nothing difficult or weird with what you want, you just have to use a small enough increment.
I understand that I can subdivide the curve down so that I am drawing single pixel lines, but that is again drawing lines. What I am looking for is Bezier curve code that draws a Bezier similarly to Bresenham's line drawing code. In other words, the initial pixel is calculated and the rest are incrementally derived from some function. The curve would be plotted pixel by pixel by pixel.

My interest in this is really just personal. I have no need for it, but it always bothered me that I could not find any examples. I am just really curious if this has ever been done, and if so, I would like to see the code.

When I started programming at age eight on a 68000-based Mac, I was fascinated by QuickDraw's ability to draw geometric shapes so quickly. This led to years of searching as to how (I started well before the internet was established). I now have an admittedly pointless, but interesting cache of pixel-perfect (midpoint) geometric object drawing code (ellipses, elliptical arcs, lines, etc.). This kind of became a hobby of mine.

That'd be an interesting bunch of code, regardless of the language they were written in. Do you them up on a website somewhere where I could peruse them?

That'd be an interesting bunch of code, regardless of the language they were written in. Do you them up on a website somewhere where I could peruse them?


I have them floating around my hard drive somewhere. They all came from the internet, either in whole or part and most are easy to find. The only difficult one was the elliptical arc code. It took years for me to find a reference on how to do that and modify my ellipse drawing function. If I have time, I'll clean them up and post them.

I understand that I can subdivide the curve down so that I am drawing single pixel lines, but that is again drawing lines. What I am looking for is Bezier curve code that draws a Bezier similarly to Bresenham's line drawing code. In other words, the initial pixel is calculated and the rest are incrementally derived from some function. The curve would be plotted pixel by pixel by pixel.

My interest in this is really just personal. I have no need for it, but it always bothered me that I could not find any examples. I am just really curious if this has ever been done, and if so, I would like to see the code.


Well, if your line segments are only a single pixel long they're... uh.... just pixels. They're sequentially plotted from the function that is the Bezier curve. You're probably not going to find something as simple and elegant as a Bresenham algorithm for Bezier curves because the curvature is neither constant like a circle, nor easily predictable like an ellipse. You could possibly derive it to obtain the curvature (the curvature can be described as the rate of change of the tangent to the curve with respect to the arc-length, or dT/ds) and match curvature to a pixel pattern, but that just seems needlessly complex. Some quick googling turned up http://www.gamedev.net/topic/156180-curvature-of-a-bezier-solved/ in which a poster posted about how to find the curvature of a Bezier; couldn't say how accurate or correct it is, but it might be a place to start. Seems like, if you know the curvature at pixel N, then you should be able to use it to calculate pixel N+1. But, again, it's probably just easier to evaluate the curve for very small increments of t instead.
That makes sense. Thanks.
All midpoint algorithms describe the curves with an equation in the form f(x, y) = 0 (with integer or rational* coefficients). A Bézier curve is not in this form. It is a parametric equation in the form (x, y) = P(t). However, it is always possible to transform a Bézier curve to the required form. In the case of a quadratic (or maybe also cubic) curve it may be practical. In general it is probably easier and faster to simply use the subdivision idea. Note that a quadratic Bézier curve is an arc of parabola, so you need an algorithm to draw it if you want to draw a quadratic Bézier curve.

* A polynomial with rational coefficients can be easily converted to a polynomial with integer coefficients by multiplication by an integer constant.

All midpoint algorithms describe the curves with an equation in the form f(x, y) = 0 (with integer or rational* coefficients).


I haven't seen this; I always just see lines, circles, and ellipses -- and I guess conic sections most generally. I assume you mean that f is any polynomial function of x and y (with rational coefficients)? Then is the idea that the state of the algorithm is all the x[sup]i[/sup]y[sup]j[/sup] products or something? I don't see how this works beyond the quadratic case, because the coefficients in Pascal's triangle stop being 1s and 2s (so you lose the fast bit-shift multiplication, and besides, the number of items in each row of Pascal's Triangle grows with O(n), whereas you can just compute the powers directly in O(log(n)) by repeated squaring). Maybe you could point me to a reference?
I do not know special algorithms outside lines, circles, ellipses and conic sections. However, I think any "midpoint algorithm" to rasterize a curve defined by the implicit equation f(x,y) = 0 follows the following steps:

  1. Choose an initial point
  2. Choose the two candidate next points (from the points adjacent to the current one) based on the derivative of the curve at the current point
  3. Evaluates the function f at the midpoint of the two candidate points
  4. Choose the next point based on the sign of the value computed at 3
  5. Repeat steps 2-5 until the last point is rendered

This general algorithm comes from my general understanding of the algorithms and not from some reference. However, looking for relevant papers on Google I have found "Rasterization of Nonparametric Curves" by John D. Hobby. I haven't read it but the abstract is the following:

We examine a class of algorithms for rasterizing algebraic curves based on an implicit form that can be evaluated cheaply in integer arithmetic using finite differences. These algorithms run fast and produce “optimal” digital output, where previously known algorithms have had serious limitations. We extend previous work on conic sections to the cubic and higher order curves, and we solve an important undersampling problem.[/quote]

This topic is closed to new replies.

Advertisement