Bézier Circles
and other shapes

The Fun with Numbers Series

by G. Adam Stanislav

Bézier Circles and other shapes
A book in the Fun with Numbers series.

Copyright © 2014 G. Adam Stanislav.

All rights reserved. No part of this book may be reproduced or transmitted in any form by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the author.

Published by Time Travel Press logo Time Travel Press.

Smashwords edition.

Mathematical notation typeset in LaTeX.

Thank you for downloading this ebook. This book remains the copyrighted property of the author, and may not be redistributed to others for commercial or non-commercial purposes. If you enjoyed this book, please encourage your friends to download their own copy from their favorite authorized retailer. Thank you for your support.

Drawing a Circle with Bézier Curves

Introduction

If you have come to the conclusion it is not possible to draw a perfect circle using Bézier curves, well… You are right.

Fortunately, the human eye does not have to be looking at a perfect circle for the human mind to say: “Hey, that is a circle.”

So, while you indeed cannot draw a circle using Bézier curves, you can emulate one very closely.

Why draw circles with Bézier curves?

That is a perfectly legitimate question. Why should you use Bézier curves to emulate a circle, when you can draw one using just about any graphics library?

The answer is simple: Sometimes you cannot. For example, if you are designing a Postcript font (such as the now popular OTF type), you are limited to very few graphics primitives: You can draw a line, and you can draw a curve. A cubic Bézier curve, to be more specific.

I originally wrote this in 1998 and posted it on my website, where you can still see it. The comment about the “surprisingly few resources” was true back then. (In this 2014 ebook I have inserted annotations in parentheses and in this color. They were not in the original 1998 text.)

Resources

There are a surprisingly few resources in computer graphics literature explaining how to use Bézier curves to emulate a circle. In all the years of studying computer graphics, (as of 1998) I have seen only one book that touched the topic. And it came up with a wrong solution.

Yet, someone has figured it out. Just about any major commercial drawing program which allows you to export a graphic as a glyph of a Postcript font will do it properly. But, for whatever reason, they do not seem to let others know how they do it.

Several years ago (i.e., several years before 1998), I decided to solve the puzzle, based on the knowledge of basic geometry and principles of computerized typesetting. After I solved the puzzle, I posted the solution in one of Fidonet’s discussion groups (Laserpub).

Many have thanked me for the solution, yet the knowledge seemed to remain with those who read my message.

That is why (in 1998) I have decided to post the solution here on this Internet page (and in 2014 in this ebook).

Analysis

Let us consider some basic properties of a circle:

A circle is a set of points on a plane, each equally distant from a center point. If we run a vertical line through the center, we divide the circle into two semicircles, each of which is the exact mirror image of the other. We can do the same using a horizontal line.

If we use both, a vertical and a horizontal line, we divide the circle into four sections, all mirror images of the rest (the mirror can be horizontal, vertical, or both).

That means that if we can figure out a way to draw one of the quadrants, we know how to draw all four of them.

Secondly, if we draw 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 be 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 point, an ending point, and two control points.

If we connect the starting point with the nearest control point, and the ending point with its nearest control 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 is an infinite number of curves that have these properties (since there is, at least in theory, an infinite number of lengths l we can use). None of them will yield a perfect circle.

Solution

As I said in the introduction, we cannot draw a perfect circle but we can produce a very close approximation. The trick is in finding the right l.

The value of l is different for each circle, depending on its radius r. That is not a problem. All we need to do is find the l for the special case where r = 1. The result will be a constant, which I shall call kappa (the first letter of the Greek word kyklos, circle). It is hard on the Internet to draw Greek letters, so I am transliterating it as kappa.

Once we have determined the value of kappa as being the l of a circle with r = 1, we can emulate any circle of radius r by using the formula:

l = r . kappa

The Right kappa

The right value of kappa will draw a curve that is as close to a quadrant of a circle as we can get. It is my contention that we get the closest to a real circle if we draw the one curve with properties already discussed, and with the center point of the curve lying at the same point that the center point of the circumference of a true quadrant of a circle would lie at.

I am not going to bore you with the details of deriving the value of such a kappa. I will just say that:

kappa = 0.5522847498

Simple as 1-2-3-4

Unfortunately, kappa is not a rational number. But you do not have to memorize its value to use it, nor do you you have to come back here every time you need to use it.

Fortunately, the formula to derive kappa is very simple: Just remember the phrase “As simple as 1-2-3-4”. That will help you in remembering the full formula which I will describe verbally:

Subtract one
from the square root of two,
divide the result by three,
and multiply by four.

Summary

To emulate a near perfect circle of radius r with cubic Bézier curves, draw four curves such that one of the line segments connecting the starting point with the nearest control point, or the ending point with its nearest control point, is vertical, while the other one is horizontal. The length l of each such segment equals r multiplied by kappa.

To draw an ellipse, follow the same rule. But you will 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 control point. If the radii of the ellipse are not horizontal and vertical, you will need to rotate the result using methods described in just about any computer graphics handbook.

The Proof of the kappa

Introduction

Both, my original Fidonet posting and my 1998 web page, were aimed at vector graphic artists. Most of them were not interested in how I determined the value of kappa. They were just happy to have a way of producing good looking circles using nothing but cubic Bézier curves, which were back then, as they are now, the main method of creating vector graphics.

Eventually, however, some people agreed it looked right but were wondering if it really was the right value, or if I had just pulled it out of my fedora. That was a fair question, as in mathematics any claim needs to be proven. So, in 2005 I added another page which showed the proof. But, due to my failing health at the time, I did not make that page as detailed and thorough as I wanted. I am going to do that here and now, in this chapter.

But first, let’s take a brief look at how vector graphics work. If you know the mathematics of vector graphics in general and Bézier curves in particular, feel free to skip to the proof. Otherwise, keep reading.

The Plotter Analogy

One of the earliest devices used to create a vector image was the plotter. A plotter can produce two-dimensional plots (line drawings) by moving a sheet of paper (or some other surface, such as plastics) forward and backward and a pen or a knife leftward and rightward. The paper movement represents one axis, the pen another. The two axes represent the two dimensions of a two-dimensional drawing. Their respective movements are independent of each other.

But both movements are a function of time, that is, the movements start somewhere along the axes at time t = 0 and continue, again independently of each other, at discrete increments, toward some final time, say, t = 1. By breaking the movements into small chunks, simple line or curve segments, each defined as starting at t = 0 and ending at t = 1 (a different t = 0 and t = 1 for each segment), a very complex graphic, such as the picture of a Bratislava street on the left, can be plotted as a series of very simple movements.

This fact of the movement along each axis being independent of each other but dependent on time is the heart of the way vector graphics work.

Parametric Equations

You are probably familiar with the mathematical concept of a function with an independent variable x and a dependent variable y, usually expressed as y = f(x), meaning y is a function of x, which maps at most one value of y to each value of x. By themselves, such functions would not be useful in computer graphics, where we often require a number of values of y for any value of x.

The problem is solved by the use of parametric equations which, like the plotter, make both, the x (horizontal) and the y (vertical), axes dependent on time (typically marked u) but not on each other. And the variable u is only used within a limited range, from some lowest value to some highest value, so it only describes a curve segment rather than some unbound curve, which would perhaps expand from infinity to infinity. For example, the parametric equation of a circle of radius r is:

The notation after these two equations (right before the equation numbers) means the equations are valid for any u from negative pi to positive pi, inclusive. Outside that range the equations must not be used to draw a circle. A real life renderer would evaluate them in many small steps. How many steps? That depends on the resolution of the device to render the circle to—the higher the resolution, the more and the smaller the steps.

Many digital graphics engines, especially the early ones, are not capable of calculating the sine and the cosine, but all are perfectly capable of addition and multiplication. That is why vector graphics are often limited to forming curve segments by using cubic parametric equations. A cubic equation can be easily computed by using Horner’s rule, a total of three additions and just as few multiplications, like this:

A two-dimensional cubic curve segment can then be expressed in the parametric form thus:

The notation after these two equations—and many other equations to come—means the equations are only valid for any u from 0 to 1, inclusive. Outside that range, the equations cannot be used to draw whatever curve segment the equations are describing. Another way of saying the same is, the equations are valid if and only if 0 <= u <= 1, that is, if and only if u is greater than or equal to 0 and lesser than or equal to 1.

While this is the standard mathematical way of describing a cubic curve segment, for the u between 0 and 1 inclusive, it is very non-intuitive for a graphic designer, as it makes it difficult to visualize what the curve segment described this way actually looks like. Sure, we can easily determine the starting and ending point of the curve segment. Since at the starting point u = 0, we can tell that the a, b and c constants are all multiplied by a zero at the starting point, and only the d constant is unaffected. Therefore, the curve segment starts at x(0) = dx and at y(0) = dy.

And since at the end of the curve segment u = 1, we can tell the coordinates of the final point will equal a + b + c + d. Therefore, the curve segment ends at x(1) = ax + bx + cx + dx and y(1) = ay + by + cy + dy. But we do not know how it gets from the start to the end, i.e., we do not know what the shape of the curve is. Actually, to be fair, a mathematician can have a good idea of what the curve looks like, but most of the rest of us…

To illustrate this difficulty, I am asking you to consider this specific example:

Just by looking at the two equations, we can tell this curve segment starts at x = 180 and y = 180 coordinates. From equation (6) we can calculate that it ends at x = - 60 + 90 + 90 + 180 = 300, which is to the right of the starting point. And from equation (7) we can also calculate that it ends at y = 633 - 783 + 270 + 180 = 300, which is above the starting point. But while we can determine the starting coordinates of [180,180] just by looking at the equations, the values of the ending coordinates of [300,300] appear nowhere in either equation and have to be calculated. Depending on how good you are at math, you may need to use a calculator to do that.

What’s worse, there is no intuitive way for most of us, yours truly included, to tell the shape of the curve. Is it concave? Is it convex? Or does it start off concave, then change to convex? Or perhaps starts off convex, then changes to concave? As the image shows, it is the latter. But there are many other possibilities. The curve could be forming a loop, or it could look like the head of a mushroom, etc. But none of that is obvious from the standard parametric cubic equations.

Worst of all, however, a graphic designer with a certain shape in mind cannot even start guessing what values a, b and c should have. He only knows what d should be, since it determines the starting point of the curve segment.

Cubic Bézier Curves

It is much more convenient and intuitive to express cubic parametric equations as cubic Bézier curves, which describe the curve segments using four points—p₀, p₁, p₂ and p₃—where p₀ lists the x and y coordinates of the starting point of the curve segment, just as dx and dy do in equations (4) and (5). Point p₃ lists the coordinates of the ending point of the curve segment, which we had to calculate on our own when using the form of equations (4) and (5).

The remaining two points, p₁ and p₂, control the shape of the curve segment. The line p₀p₁ is tangent to the start of the curve, showing the direction in which the curve is moving at the beginning. Its length controls how fast the curve is curving at the beginning. In our example the line is relatively short, so the curve starts off curving slowly and does not move far from the starting point before the other control point starts affecting it. The position of p₁ relative to the line p₀p₃ determines the flatness (or straightness) of the beginning of the curve segment, as well as its convexity or concavity. If it was lying on the p₀p₃ line itself, the tangent of the start of the segment would be the same as the overall direction of the curve (which the p₀p₃ line shows) and the start of the curve would, therefore, look like a straight line. In our example, the curve starts off convex, though the convex portion of the curve is much smaller than the concave rest of the curve, which is also seen by the triangle p₀p₁Q being much smaller than the p₃p₂Q triangle.

The p₂ control point affects the ending of the curve segment. It does for p₃ what p₁ does for p₀. Because, in our example, the length of p₂p₃ is much greater than the length of p₀p₁, and the p₃p₂Q triangle is much larger than the p₀p₁Q triangle, the ending concavity is much more pronounced than the initial convexity.

Since the p₁p₂ line crosses the curve, we can also know (even if we did not have the picture) that the curve changes between convexity and concavity. It does so at the point where p₁p₂ crosses the curve.

Advanced Topic: The point where p₁p₂ crosses the curve is called the point of inflection. Its coordinates can be calculated using calculus and vector mathematics as , where is the derivative of p and is the second derivative of p. In a parametric cubic equation with , and . It is way beyond the scope of this book to go more into it.

Clearly then, a cubic Bézier curve is much more intuitive to a graphic designer than just a standard cubic curve. That is why just about all graphics software uses Bézier curves. The designer can simply draw a curve segment from the starting point p₀ to the ending point p₃ and adjust the shape of the curve segment by moving the p₁ and p₂ control points (which such software usually refers to as the “handles” of the curve; it also usually just refers to the curve segment as a “curve”, dropping the word “segment”).

It is no harder on the digital graphics engines to render cubic Bézier equations, as, after applying Horner’s rule (3), it still involves only one extra operation other than addition and multiplication, namely negation. The cubic Bézier formula is:

That is a shortcut way of saying p(u) = (1-u)³p0 + 3u(1-u)²p1 + 3u²(1-u)p2 + u³p3

Summation is the summation symbol. It tells us to add up whatever formula follows, and to do so for every i from 0 to 3.

0! = 1, 1! = 1, 2! = 2 and 3! = 6, so t₀ = 1, t₁ = 3, t₂ = 3 and t₃ = 1. If that makes no sense to you, see Factorial on Wikipedia.

Since cubic Bézier equations are just a different way of expressing standard cubic equations, any standard cubic equation can be converted to a cubic Bézier equation, and any cubic Bézier equation can be converted to a standard cubic equation. So, an alternative for a digital graphics engine is to convert the cubic Bézier curve to a standard cubic curve before rendering it. That will allow it to render faster and use less memory in the process.

I will discuss the conversion in another chapter, but for now here is what our example curve segment from equations (6) and (7) converts to in the cubic Bézier notation. Please note that p₀, p₁, p₂ and p₃ are two-dimensional vectors, or 2-tuples, or doubles, or two-dimensional arrays, depending on whom you ask. At any rate, the first number is for the x axis, the second for the y axis.

And now we can easily draw the curve. For example, we can create an SVG graphic like this:

<?xml version='1.0'?> standalone="no"

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<!-- Copyright © 2014 G. Adam Stanislav -->

<svg height='124pt' version='1.1' viewBox='0 -124 124 124' width='124pt' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>

<g transform='matrix(1 0 0 1 -178 178)'>

<path d='M180 -180C210 -270 270 -99 300 -300' fill='none' stroke='#660000' stroke-width='2.0'/>

</g>

</svg>

It’s as simple as that!

Note that here we have expressed the y coordinates as negative numbers. That is because in SVG y = 0 is on the top of the screen, while in Bézier curves y = 0 is at the bottom of the screen. If we used EPS, we would not need to negate the y coordinates:

%!PS-Adobe-3.0 EPSF-3.0

%%BoundingBox: 178 178 302 302

%%Pages: 0

%%Creator: G. Adam Stanislav

%%CreationDate: September 6, 2014

%%EndComments

%%EndProlog

newpath

2 setlinewidth

180 180 moveto

210 270 270 99 300 300 curveto

stroke

showpage

%%EOF

Unlike with SVG, in our EPS code we did not set the color. That is because of the different nature of the two formats. SVG defines a full, self-standing graphic meant to be shown at a computer (or computer-like device) monitor. EPS defines a graphic that is meant to be encapsulated in some other PostScript file, so by leaving the color undefined, we give the author of the PostScript file the freedom to use any color he wants. And if he does not, it will default to black.

The kappa

We can now prove that kappa = 4*(sqrt(2)-1)/3 is true.

Please note that regardless of the value of the radius r, given the definition of the circle as a set of points all being of the same distance from its center, marked O in the image. That distance is the radius of the circle. So, in our image the lengths of OA, OB, as well as OC is r. Additionally, the line AA’ is parallel with the line OB and is, therefore, vertical. Similarly the line BB’ is parallel to the line OA and is, therefore, horizontal. The length of both, AA’ and BB’ is l=r*kappa.

Also please note that using Bézier curves we have two ways of drawing the upper right quadrant of the circle. One way is to draw it counterclockwise, so, as per equation (8), p₀ = A, p₁ = A’, p₂ = B’, and p₃ = B. The other is to draw it clockwise, so p₀ = B, p₁ = B’, p₂ = A’, and p₃ = A. While the result happens to look the same in this particular image, sometimes we need to draw one way or the other, as it affects how a closed path is filled. Either way, though, the coordinates of A, A’, B’ and B remain the same. So, if we prove the validity of kappa = 4*(sqrt(2)-1)/3 for drawing it one way, we have proven it for the other.

In the Drawing a Circle with Bézier Curves chapter, I stated the following axiom:

“The right value of kappa will draw a curve that is as close to a quadrant of a circle as we can get.It is my contention that we get the closest to a real circle if we draw the one curve with properties already discussed, and with the center point of the curve lying at the same point that the center point of the circumference of a true quadrant of a circle would lie at.”

In the figure to the right, the center point is marked C. Its coordinates are cx and cy. Because cx lies on the x coordinate, . And because cy lies on the y coordinate, .

From that we know that both, and , are right triangles. Additionally, cx = cy, which means both, and , are isosceles triangles.

means the line going through the points C and cx is perpendicular (at the right angle) to the line going through the points O and cx.

Similarly, means the line going through the points C and cy is perpendicular to the line going through the points O and cy.

means the triangle produced by connecting the points O, C and cx. And means the triangle produced by connecting the points O, C and cy.

From that, using the Pythagorean theorem, we can calculate the value of both cx and cy in a real circle drawn by equations (1) and (2), for a circle of any radius r. And since cx = cy, we will just use a c to represent both:

Line (17) is just another way of expressing the result in line (16), obtained by multiplying both, the nominator and the denominator of (16), by the square root of two. Not only does (17) look better to us humans, it is also a lot easier to compute than (16), both by humans and computers. Both are the correct solution for the value of c = cx = cy. We can use whichever we prefer, or whichever makes our calculations clearer.

Now we are ready for our first proof. For starters, let us assume that, in the image on the right, we have a circle with the radius r = 1. Going counterclockwise, the coordinates of the four points are:

We will only be concerned with one axis for our first proof, let’s choose x, whose coordinates are:

If we plug these values into equation (8) and kappa is valid, the calculation of x(0.5) must give us the value of cx which, given that r = 1, must equal sqrt(2)/2. And since 1 - 0.5 = 0.5, we will replace all occurences of u^n*(1-u)^(3-n) with the constant 0.5³=0.125. Here then is the calculation:

Since x(0.5) =sqrt(2)/2 =c, this calculation proves that kappa = 4*(sqrt(2)-1)/3 is correct, at least for the x axis when drawing counterclockwise when r = 1, and also for the y axis when drawing clockwise, and r = 1, because the only difference between a clockwise and a counterclockwise drawing is that clockwise y = counterclockwise x.

Now that we understand the mathematical principles behind Bézier curves, we are ready to move on to prove that kappa = 4*(sqrt(2)-1)/3 is the right value of kappa for the emulation of the circle of any radius r.

The Proof

To prove that kappa = 4*(sqrt(2)-1)/3 is the right value of kappa for the emulation of the circle of any radius r, we will calculate equation (8) with the values of u = 0.5 where the lengths of both AA’ and BB’ is l=r*kappa. We will do so separately for the x axis and the y axis. If necessary, we will do so for both, the clockwise and the conterclockwise, use. It will only be necessary if their four p points are different. So, for example, if we find that the counterclockwise x is the same as the clockwise y and the counterclockwise y is the same as the clockwise x, it will not be necessary, since in that case the proof that kappa = 4*(sqrt(2)-1)/3 is the right value for the x axis of a counterclockwise drawing also proves it is the right value for the y axis of a clockwise drawing. And if we prove it is the right value for the y axis of the counterclockwise drawing, it also proves kappa = 4*(sqrt(2)-1)/3 is the right kappa for the x axis of a clockwise drawing.

If, in every case the result of the calculation equals r*sqrt(2)/2, as required by (17), then and only then is kappa = 4*(sqrt(2)-1)/3 the correct value of kappa for any radius r. Otherwise, it is not.

Also please note that our proof only concentrates on circles with O = [0 0]. This is because translating a drawing (i.e., moving its center to some other position) does not affect its shape. A circle remains a circle no matter where we move it. So our proof is valid even for any Bézier circle regardless of the position of its O.

Here are the values of p for any counterclockwise circle with radius r using our kappa:

And here are the values of p for any clockwise circle with radius r using our kappa:

As you can see, the x axis of the clockwise circle is the same as the y axis of the counterclockwise circle. And the y axis of the clockwise circle is the same as the x axis of the counterclockwise circle. Considering the symmetry of a circle, this is not surprising at all.

It also means that proving the validity of kappa = 4*(sqrt(2)-1)/3 for the counterclockwise circle also proves it for the clockwise circle. Again, this is not surprising since a circle is a circle no matter what direction we chose to draw it in. We will, therefore, only provide the proof for the counterclockwise values.

As before, we will replace all occurences of u^n*(1-u)^(3-n) with the constant 0.5³=0.125. For the counterclockwise x axis, as well as for the clockwise y axis, our calculation will be:

And for the counterclockwise y axis, as well as the clockwise x axis:

We have shown that for any value of radius r, on both, the x axis and the y axis, counterclockwise or clockwise p(0.5) = r*sqrt(2)/2. Therefore, kappa = 4*(sqrt(2)-1)/3 is the correct value to emulate a circle with cubic Bézier curves.

QED

A Visual Test

We can easily test it visually. Here is, test.eps, an encapsulated PostScript file that draws a seven-point thick circle using the kappa, then draws a two-point thick red circle over it using the PostScript arc command. The picture on the right shows how it is rendered with PS_View, a free PostScript previewer. As you can see, the two circles overlap perfectly, producing the illusion of a red circle inside a black frame.

%!PS-Adobe-3.0 EPSF-3.0

%%BoundingBox: -104 -104 104 104

%%Creator: G. Adam Stanislav

%%CreationDate: September 13, 2014

%%EndComments

%%EndProlog

/kappa {

2 sqrt

1 sub

4 mul

3 div

} bind def

/lpos { % r * kappa

100 kappa mul

} bind def

/lneg { % -r * kappa

-100 kappa mul

} bind def

newpath

7 setlinewidth

% First Quadrant

100 0 moveto

100 lpos

lpos 100

0 100 curveto

% Second Quadrant

lneg 100

-100 lpos

-100 0 curveto

% Third Quadrant

-100 lneg

lneg -100

0 -100 curveto

% Fourth Quadrant

lpos -100

100 lneg

100 0 curveto

closepath

stroke

newpath

2 setlinewidth

1 0 0 setrgbcolor

0 0

100

0 360 arc

stroke

showpage

%%EOF

Playing with the kappa

Introduction

Now that we have determined kappa = 4*(sqrt(2)-1)/3 is the right kappa to draw a circle, let’s play with it a little and see what kind of other shapes we would get if we multiplied or divided it by several small prime numbers.

A prime number is an integer greater than 1 that can only be divided by 1 or by itself and still give an integer result. Ancient Greeks loved prime numbers, especially the small ones, such as 2, 3, 5, 7 and 11. It so happens I love them, too.

We can do that by simply modifying the definition of the kappa variable in our test.eps from our last chapter. To recapture, this was the relevant section of test.eps:

/kappa {

2 sqrt

1 sub

4 mul

3 div

} bind def

Dividing the kappa

Let’s start our experiments by dividing the value of kappa by the first prime number 2. To do so, we simply multiply the 3 before the div by 2 and replace it with the result, 6, like this:

/kappa {

2 sqrt

1 sub

4 mul

6 div

} bind def

The result, as the picture on the right shows, is no longer a circle. It is a sort of a rounded square with its corners on the top, left, bottom and right. It is completely inside the red circle, touching it at the four corners.

In the image, it appears the four corners actually extend beyond the red circle. This is because we have set the line width of the red circle to two PostScipt units and the width of the test image to seven PostScript units. If they were both of the same line width, the test image would be touching the red circle at the four corner points. It would not extend beyond it.

This is true in all of our examples of this chapter. After all, in our test.eps we have set the four corners to lie exactly at the radius distance from the origin O. And by the definition of a circle, all of the red circle’s points lie exactly at the radius distance from the origin O. Therefore, the four corners of any of our tests, in this chapter, can lie neither outside nor inside the red circle. They always lie on the circle.

All the rest of our test points will lie inside the circle when we use a length lesser than the radius multiplied by the kappa (as in our division tests) and outside the circle when we use a length greater than the radius multiplied by the kappa. As we have seen in the last chapter, when we use the length equal to the radius multiplied by the kappa, then and only then do all the points lie on the circle. In none of these cases do the test images cross the circle.

Give yourself extra credit if you can tell what would happen if we used a value greater than the radius multiplied by the kappa on the x axis and lesser than the radius multiplied by the kappa on the y axis. And what would happen if one of the axes used a value equal to the radius multiplied by the kappa and the other would not? If you are not sure, rewrite test.eps to try it. Better yet, try it even if you think you are sure.

While it is not a circle, it is still a shape we may use in graphics design. Let’s play with it a little more by adding the following right before the first newpath in our test.ps:

45 rotate

This will rotate the entire drawing by 45° counterclockwise. The result, seen on the left, is a shape we may want to use for a web button, just to name one example. Or perhaps a very old TV, to name another.

Now, let’s delete the 45 rotate statement and see what happens if we try dividing the kappa by 3. Since 3*3 = 9, we need to place a 9 before the div, like this:

/kappa {

2 sqrt

1 sub

4 mul

9 div

} bind def

The result, on the right, does not look that much different from when we divided kappa by 2. But it is flatter than that, so it is different.

Moving on, the next prime number is five, so we change our divisor to 5*3 = 15, like this:

/kappa {

2 sqrt

1 sub

4 mul

15 div

} bind def

Again, the result, on the left, is flatter than before. That brings about the question, will it ever be completely flat, so that it is just a square with no roundness.

The answer is that theoretically it will never become completely flat. Practically, however, we are dealing with outputting the drawings on physical devices, whether in print or on a monitor. Because these devices have a limited resolution, they will all come to a point where the roundness is too subtle for them to render. At that point, and anything beyond, the rendered image will become a regular flat square, albeit with its corners on the top, left, bottom and right. Of course, as we have seen, we can rotate the image to our liking.

For our final division of kappa, the picture on the right shows what would happen if we divided kappa by the next prime number, 7. We would do so by setting the value of the div operator to 7*3=21. This image is hard to distinguish from the previous one. If we pressed on with more divisions, we would see less and less difference, so we will stop here and move on to experimenting with multiplying the kappa instead.

I will still point out, however, that while the differences may be too small for graphic design, going further and then showing all the images in sequence on a video would make for a very nice animation. If you want to do that, the Math Is Fun web site has a list of prime numbers from 2 to 9973. There are many such sites, just search the web for list of prime numbers to find them.

Multiplying the kappa

To experiment with multiplying the kappa we need to restore the value before the div operator of test.eps to 3. We will proceed to multiply the 4 before the mul operator by various small prime numbers.

While before we saw the results appear inside the red circle, now we expect them to expand outside of it, while still touching it at the same four points as before. Additionally, the images will grow, so we will probably have to change the bounding box in the second line of our file. But not yet with our first experiment.

For the first prime number, 2, we need to multiply the 4 by 2, and change the 4 to 8:

/kappa {

2 sqrt

1 sub

8 mul

3 div

} bind def

The result, on the left, looks like a square with rounded corners. But is it? There is only one way to find out, by plugging 2*kappa into our trusted equation (8) and calculate the result of p(0.5). If the result is greater than the radius r, the looks are deceiving as it means the vertical lines have to move to the right in the first and fourth quadrant and to the left in the second and third quadrant before curving. Similarly the horizontal lines with moving up or down.

If, on the other hand, the result is less than the radius r, especially slightly less, using 2*kappa would give us a really nice and elegant way of producing a square with rounded edges.

So let’s do the math:

We would get the same result had we calculated it for the y coordinate. Feel free to calculate it if you don’t believe.

Since 0.91421 is slightly less than 1, we can use 2*kappa to create a smooth shape the human eye cannot distinguish from a square with rounded corners any more than it can tell kappa from a circle.

On the right you can see the result of the same test.eps, just without the red circle and without setting the line width to 7. Oh, and without going through PS_View.

Moving on to 3*kappa, we set the multiplier to 3*4=12, like this:

/kappa {

2 sqrt

1 sub

12 mul

3 div

} bind def

But we also need a bigger bounding box, so we change the second line of test.eps to this:

%%BoundingBox: -118 -118 118 118

That is because, as the image on the left shows, we are now extended way out from the square around the original circle. Without changing the bounding box our drawing would be clipped.

This is another smooth shape we can use the kappa for, by simply multiplying it by three.

The next prime number is five, so we set the multiplier to 5*4= 20.

/kappa {

2 sqrt

1 sub

20 mul

3 div

} bind def

Once again, we have to enlarge our bounding box for that:

%%BoundingBox: -162 -162 162 162

This time p(0.5) is clearly so much larger than the radius r that the curve loops at the four edges. Yet it does so without the need to insert any additional Bézier curves. Producing loops is a perfectly acceptable use of Bézier curves.

There is an exception in designing fonts, as these would look good while filled, but not when stroked.

For our final exercise, we will use the next prime number, seven, and set the multiplier to 7*4=28.

/kappa {

2 sqrt

1 sub

28 mul

3 div

} bind def

And we will enlarge our bounding box, as we always have to as we increase the multiplier (the only exception was when we multiplied by two). All through these experiments we have been figuring out the right bounding box by trial and error, though we certainly could have calculated the p(0.5) for every new case, added half of the width of the line and rounded it up to an integer. But trial and error works just as good.

%%BoundingBox: -208 -208 208 208

As you can see, on the right, the size of the loops got larger. And if we went with further prime numbers, they would get larger and larger yet. So, once again, you may be asking whether we could go far enough to make the underlying square so small that it would disappear.

This time the answer is never. Not theoretically and not practically. The thing is, the box is actually not getting smaller as the “ears” are getting bigger. The box is always outside the red circle, and that circle never changes its size. It may appear smaller in our illustrations because we asked PS_View to always fit the bounding box in the same window.

What if we made the radius r extremely small and used a very large kappa multiplier? It still doesn’t do it. As the multiplier approaches infinity, the curves of the “ears” turn more and more into straight lines, so the desired effect just isn’t there.

Please, don’t take my word for it, though. Try it yourself!

About the Author

Born 23 April 1950 in Bratislava, Stanislav was graduated in 1968 from Gymnázium Jura Hronca in Bratislava, with specialization in mathematics and computer programming. He holds graduate degrees in psychology from Komenský University in Bratislava and in canon law from Gregorian University in Rome. His writing, both fiction and non-fiction, was published in Slovakia, Czech Republic, Italy, Vatican and the United States. He has lived in Bratislava, Český Krumlov, Vienna, Rome, Washington and Pittsburgh. He is currently retired in Wisconsin. He was active in the anti-Communist underground in Czechoslovakia until he escaped to Austria in 1979. He became a US citizen in 1990 on the same day his home country rebelled against Communism in the Velvet Revolution. He enjoys visiting his beloved Bratislava as often as his financial situation and his failing health permit.

Also by this Author

Precious Ratios

For thousands of years mathematicians and artists studied the golden ratio. Later they developed the silver ratio. An ebook in the Fun with Numbers series, published by Time Travel Press, Precious Ratios develops the general formula for creating any number of precious ratios, compatible with the ideas behind the golden and silver ratios. As an example, it shows how to create and compute the values of the iridium ratio and the platinum ratio. It includes C++ classes to compute the value of any precious ratio, and a sample C++ code showing how to use the classes.

Look for Precious Ratios at your favorite ebook retailer or ask for it in your local library. Its ISBN is 978-0-9716461-0-0.