Thread View: comp.sys.next.programmer
4 messages
4 total messages
Started by Matt Brandt
Mon, 11 Jan 1993 01:42
Arcs and circles from curveto
Author: Matt Brandt
Date: Mon, 11 Jan 1993 01:42
Date: Mon, 11 Jan 1993 01:42
15 lines
909 bytes
909 bytes
I've been able to come up with a pretty good approximation of a circle using curveto that works like this: x y rad 0 180 arc is approximately equivalent to: x-rad y x-rad y+2*rad/3 x+rad y+2*rad/3 x+rad y curveto of course, you can repeat for the bottom of the circle. Like I said though, this is only an approximation. Does anybody out there have a better approximation of circle drawing using curveto? I need to do it this way for bizarre reasons and I would like to improve the accuracy a little bit. matt
Re: Arcs and circles from curveto
Author: Eric P. Scott
Date: Tue, 12 Jan 1993 02:25
Date: Tue, 12 Jan 1993 02:25
15 lines
936 bytes
936 bytes
PostScript approximates each quadrant of a circle with a curveto. e.g. If you do a pathforall against 0 0 125 0 360 arc, you should find something like: 125 0 moveto 125 69 69 125 0 125 curveto -69 125 -125 69 -125 0 curveto -125 -69 -69 -125 0 -125 curveto 69 -125 125 -69 125 0 curveto BTW, This question properly belongs in comp.lang.postscript; it's not the least bit NeXT-specific. -=EPS=-
Re: Arcs and circles from curveto
Author: Henry McGilton
Date: Tue, 12 Jan 1993 17:51
Date: Tue, 12 Jan 1993 17:51
33 lines
1791 bytes
1791 bytes
In article <1993Jan11.014246.4735@drefla.mese.com> matt@drefla.mese.com (Matt
Brandt) writes:
* I've been able to come up with a pretty good approximation
* of a circle using curveto . . .
<<<<< stuff deteleted >>>>>>
* of course, you can repeat for the bottom of the circle.
* Like I said though, this is only an approximation. Does
* anybody out there have a better approximation of circle
* drawing using curveto? I need to do it this way for bizarre
* reasons and I would like to improve the accuracy a little bit.
You can't get an accurate enough circle with only two curves. You
need one curve per quadrant, and you draw four of them. The ``magic
number'' for the circle is 0.555. Here's an example which you
can hack to your needs.
%!PS
/R 288 def
/M R 0.555 mul def
306 396 translate
R 0 moveto
R M dup R dup 0 exch curveto
M neg R dup neg M R neg 0 curveto
R neg M neg dup R neg dup 0 exch curveto
M R neg R M neg R 0 curveto
closepath
stroke
I cross posted this to comp.lang.postscript, because, as Eric Scott
pointed out, this topic is pure PostScript and only tangentially
NeXT related.
........ Henry
Re: Arcs and circles from curveto
Author: Berthold K.P. Horn
Date: Wed, 13 Jan 1993 02:25
Date: Wed, 13 Jan 1993 02:25
92 lines
4427 bytes
4427 bytes
In article <1993Jan12.175132.27149@trilithon.mpk.ca.us> henry@trilithon.mpk.ca.us (Henry McGilton) writes:
In article <1993Jan11.014246.4735@drefla.mese.com> matt@drefla.mese.com (Matt
Brandt) writes:
* I've been able to come up with a pretty good approximation
* of a circle using curveto . . .
<<<<< stuff deteleted >>>>>>
* of course, you can repeat for the bottom of the circle.
* Like I said though, this is only an approximation. Does
* anybody out there have a better approximation of circle
* drawing using curveto? I need to do it this way for bizarre
* reasons and I would like to improve the accuracy a little bit.
You can't get an accurate enough circle with only two curves. You
need one curve per quadrant, and you draw four of them. The ``magic
number'' for the circle is 0.555. Here's an example which you
can hack to your needs.
%!PS
/R 288 def
/M R 0.555 mul def
306 396 translate
R 0 moveto
R M dup R dup 0 exch curveto
M neg R dup neg M R neg 0 curveto
R neg M neg dup R neg dup 0 exch curveto
M R neg R M neg R 0 curveto
closepath
stroke
I cross posted this to comp.lang.postscript, because, as Eric Scott
pointed out, this topic is pure PostScript and only tangentially
NeXT related.
........ Henry
Addendum: Approximating circular arcs with Bezier curves:
The smaller the angle of the circular arc the better an
approximation you can get out of a Bezier curve, obviously.
For a unit radius circle, a good approximation
of an arc turning through angle theta uses
eta = (4/3) (1 - cos(theta/2)) / sin(theta/2)
where eta is the distance of the control points from the knots,
measured along a line tangent at the knots (sorry you'll
have to draw the figure yourself, my ASCII curve drawing skills
are unequal to the task).
For theta=pi/2 you get eta = (4/3)(sqrt(2) - 1) = .55228...
which yields a very good approximation to a quadrant of a circle
For theta=pi you get eta = (4/3) = 1.33333....
which is a not so good approximation of a semicircle.
In the limit as theta tends to zero, by the way, the control
points end up 2/3 of the way from the knots to the
intersection of the tangents. This is a quick and dirty way
to generate a good approximation, if breaking up an arc into
many pieces is not a concern.
By the way, the above approximations all have the Bezier curve
departing from the true arc in one direction (error always has
the same sign). One can do twice as well by balancing the
positive and the negative errors, but then no closed form
solution to the problem appears to be at hand.
For theta=pi/2 the optimum is
eta = .5541...
The same technique can obviously be used for ellipses, since
ellipses are circles on an anisotropically scaled coordinate system.
Super-ellipses can also be very well aproximated by Bezier curves
(super-ellipses have equations of the form (x/a)^beta + (y/b)^beta = 1).
Cubic `splines' are quite `flexible' since they have 8 parameters (2 knots
and 2 control points). On average, it takes twice as many quadratic splines
to describe a shape adequately as it does cubic splines.
Exercise for the reader:
Suppose you draw a pen-stroke with a pen that has a circular nib, where the
center of stroke follows a given Bezier curve. Can the `outer' and `inner'
edges of the resulting shape be described exactly using a Bexier curve?
If not, how do you compute an adequate approximation - one that does not
require splicing together too many separate cubic splines?
Berthold K.P. Horn
Cambridge, Massachusetts, USA
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads