Draw Circle With Bezier Curve
Drawing a circle with B�zier Curves
by G. Adam Stanislav
Introduction
If you lot have come up to the conclusion information technology is not possible to draw a perfect circle using B�zier curves, well... Y'all are right.
Fortunately, the human being eye does not have to be looking at a perfect circle for the human listen to say: �Hey, that is a circumvolve.�
And so, while y'all indeed cannot draw a circle using B�zier curves, you lot can emulate 1 very closely.
Why draw circles with B�zier curves?
That is a perfectly legitimate question. Why should you employ B�zier curves to emulate a circle, when yous can describe ane using only well-nigh any graphics library?
The answer is simple: Sometimes you cannot. For example, if y'all are designing a Postcript font, you are express to very few graphics primitives: You can draw a line, and you lot tin can draw a bend. A cubic B�zier curve, to exist more specific.
Resources
There are a surprisingly few resource in computer graphics literature explaining how to use B�zier curves to emulate a circle. In all the years of studying figurer graphics, I have seen merely 1 book that touched the topic. And it came up with a wrong solution.
Yet, someone has figured information technology out. Only about whatsoever major commercial drawing program which allows you to export a graphic as a glyph of a Postcript font will do it properly. Just, for whatever reason, they do non seem to permit others know how they do it.
Several years agone, I decided to solve the puzzle, based on knowledge of bones geometry and principles of computerized typesetting. After I solved the puzzle, I posted the solution in one of Fidonet�s word groups (Laserpub).
Many have thanked me for the solution, however the knowledge seemed to remain with those who read my message.
That is why I have decided to post the solution here on this Internet page.
Analysis
Let us consider some basic backdrop of a circle:
A circle is a ready of points on a plane, each equally distant from a heart signal. If we run a vertical line through the center, we carve up the circle into two semicircles, each of which is the exact mirror image of the other. We can exercise the same using a horizontal line.
If we use both, a vertical and a horizontal line, we divide the circumvolve into four sections, all mirror images of the balance (the mirror tin can exist horizontal, vertical, or both).
That means that if we tin effigy out a way to draw ane of the quadrants, we know how to draw all four of them.
Secondly, if nosotros depict a tangent to the circle at each point of intersection of our horizontal or vertical line with the circumference of the circle, the tangent itself will exist either horizontal or vertical.
If we are to emulate any of the quadrants with cubic B�zier curves (as used in Postscript fonts), we need to draw a curve which has a starting bespeak, an catastrophe signal, and two control points.
If we connect the starting signal with the nearest command betoken, and the catastrophe bespeak with its nearest command point, we will have drawn two line segments: One of them horizontal, the other vertical (depending on the quadrant).
Further, both line segments will be of the same length l.
There are an infinite number of curves that take these properties (since there are, at to the lowest degree in theory, an infinite number of lengths l we tin apply). None of them will yield a perfect circle.
Solution
As I said in the introduction, we cannot depict a perfect circumvolve but we can produce a very close approximation. The fob is in finding the right l.
The value of l is dissimilar for each circle, depending on its radius r. That is not a problem. All we demand to do is find the l for the special case where r = 1. The result volition be a constant, which I shall call kappa (the showtime letter of the Greek word kyklos, circle). It is hard on the Net to describe Greek messages, and so I am translitterating it as kappa.
One time we have determined the value of kappa every bit being l of a circle with r = 1, we tin can emulate any circle of radius r by using the formula:
The correct kappa
The right value of kappa will draw a curve that is as close to a quadrant of a circle every bit nosotros can get. It is my contention that nosotros get the closest to a real circle if we depict the 1 bend with properties already discussed, and with the center point of the curve lying at the same bespeak the center signal of the circumference of a true quadrant of a circle would lie.
I am not going to bore you with the details of deriving the value of such a kappa. I will simply say that:
Simple equally 1-2-three-four
Unfortunately, kappa is non a rational number. But you do not have to memorize its value to employ it, nor exercise you you take to come dorsum here every fourth dimension yous demand to use it.
Fortunately, the formula to derive kappa is very simple: Just remember the phrase �Equally simple equally 1-2-three-4�. That volition aid yous in remembering the total formula which I will describe verbally:
from square root of two,
divide the upshot past 3,
and multiply past four.
Summary
To emulate a nigh perfect circle of radius r with cubic B�zier curves, draw 4 curves such that one of the line segments connecting the starting point with the nearest control point, or the catastrophe signal with its nearest control point, is vertical, while the other ane is horizontal. The length 50 of each such segment equals r multiplied by kappa.
To draw an ellipse, follow the same rule. But y'all volition have two different radii: You need to multiply kappa with the radius that is parallel to the line segment connecting the starting/ending point with the nearest command point. If the radii of the ellipse are not horizontal and vertical, you will demand to rotate the result using methods described in just about any computer graphics handbook (virtually notably in Michael Mortenson�s Geometric Transformations).
Excercise
Figure out how to depict a sine wave with B�zier curves, using kappa.
Source Code
If you need to utilize kappa in your own computer software, you can download my assembly linguistic communication source code from my FTP server. You can assemble it with NASM, only it includes a preassembled object file for 32-bit Windows and another for Unix. Information technology also includes a uncomplicated C examination which just prints the value of kappa to stdout. I tested information technology with MS VC and GCC under Windows and GCC under FreeBSD.
The Mathematics
If y'all wish to run into exactly how to derive the value of kappa mathematically, read this.
Further Resources
For data how to approximate a generic arc (i.e. other than a quadrant) have a look at BEZARC1.PDF available at Guru�s Lair Cubic Spline Directory. Thanks to Izumi Ohzawa for letting me know about this link!
Copyright © 1998 G. Adam Stanislav
All rights reserved
Home
Click on the button to buy Michael Mortenson�s Geometric Transformations (an splendid book!), or to search for similar books.
Source: http://www.whizkidtech.redprince.net/bezier/circle/
0 Response to "Draw Circle With Bezier Curve"
Post a Comment