Please let me know if there's a better way.
Thanks,
Steve
Well, Bezier curves (curveto) are the obvious way, and you won't need many
segments. I've forgotten how I did it the last time, I *think* I created a
sine wave as below, imported it into Illustrator and used a built-in
function (or was it streamline?) to fit it, then fiddled that into
a Postscript function. That was expedient but inelegant. You could
probably do this numerically as well.
Best regards,
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..." "The Journey is the reward"
sp...@interlog.com Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog Info for designers: http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.BlueCollarLinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
No.
Use the following for high quality results
0. 1 setlinecap 1 setlinejoin
1. Make a digitized array of the x and y coords.
2. Use curveto to connect them
The rest, as they say, can be obtained in the PLRM.
--
Dave Blake
dbl...@phy.ucsf.edu
This answer so patently lacks utility that I was inspired to hack up the
attached Bezier approximation, which uses the first derivative and the
"thirds" rule-of-thumb to position Bezier anchors. There are much more
elegant approximations available, in fact you should be able to
approximate the first quadrant of a sine wave with just one Bezier with
sufficient accuracy for many purposes, but this was much quicker to
hack.
You should even be able to open it in Illustrator. Any questions e-mail
me.
regards
Toby
After testing "sine.ps" in Illustrator 8 - it works - I found that the
approximation is very accurate indeed. A step size of 1.0 radian is
almost indistinguishable from a step size of 0.01 radian, using the
Beziers. I would therefore describe this as an "elegant" solution. Note
that making the step size an integral fraction of a radian (e.g. pi/8)
will result in a path which can be joined end-to-end to make a sine wave
of any length.
If you redistribute or use "sine.ps", please acknowledge my authorship
(see revised file attached).
The code should also be adaptable to any similar function for which the
first derivative is known analytically (f'x).
regards
Toby
% In the second --- exact sine with 6 degrees step.
% The demo shows coincidence.
/Swave1 % N Period Amp Swave1 +currentpoint context
{ 12 sqrt mul 2 copy exch 0.4673 mul exch % 0.4673=(8-3*sqrt(3))/6
3 index 2 index sub 4 -1 roll neg 5 -1 roll 0 7 -1 roll
1 sub {6 copy rcurveto} repeat rcurveto stroke
} def
/Swave2 % N Period Amp Swave2 +currentpoint context
{ exch 60 div 0 6 dup 6 -1 roll 360 mul
{sin 3 index mul dup 3 -1 roll sub 2 index exch rlineto
} for pop pop pop stroke
} def
% Demo
/Helvetica findfont 12 scalefont setfont
10 400 80. 100. rectstroke
1 0 0 setrgbcolor [7 7] 0 setdash
10 510 moveto (False (Bezier) sine wave) show
10 400 moveto 10 80. 100. Swave1
0 0 1 setrgbcolor [7 7] 7 setdash
10 270 moveto (True sine wave) show
10 400 moveto 10 80. 100. Swave2
% Alexei Kournossenko, E-mail: Alexei.Ko...@cern.ch
% CERN, Division EST Tel: +41.22.767-4326
%----------------------------------------------------------------
--
Alexei Kournossenko, E-mail: Alexei.Ko...@cern.ch
CERN, Division EST Tel: +41.22.767-4326
CH-1211 GENEVE 23 SUISSE/SWITZERLAND Fax: +41.22.767-8890