12.07.2015 Views

PSTricks pst-bezier

PSTricks pst-bezier

PSTricks pst-bezier

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>PSTricks</strong><strong>pst</strong>-<strong>bezier</strong>A <strong>PSTricks</strong>package fordrawing Bezier curves; v.0.01January 29, 2009Package author(s):Tobias NähringHerbert Voß


Contents 2Contents1 Introduction 42 Installation and usage of <strong>pst</strong>-<strong>bezier</strong>.tex 43 The \psbcurve macro 44 Things that do not work (‘known bugs’) 85 List of all optional arguments for <strong>pst</strong>-<strong>bezier</strong> 9References 9


The <strong>pst</strong>ricks package provides (essentially) two main macros for drawing curves:\pscurve and \ps<strong>bezier</strong>. Both macros employ Bezier splines.The \pscurve macro takes multiple interpolated points as arguments. Thus, it iseasy to draw long multiply bent curves. The problem with \pscurve is that there isno easy way to change the automatically computed control points without simultaneouslychanging the interpolated points. Note that some control is possible via thecurvature option.The\ps<strong>bezier</strong>macrogivesfullcontrolovertheinterpolationpointsandthecontrolpoints of one Bezier polynominal of degree three (two interpolated points and twocontrol points).Thanksto:Jean-Côme Charpentier.


1 Introduction 41 IntroductionIf one demands for the access to certain control points of one multiply bent curveone has to use multiple instances of the \ps<strong>bezier</strong> macro. With this approache eachinnerinterpolationpointofthecurvehastobeinputtwice. Furthermore,ifoneneedssmooth joints one has to compute control points symmetrically to the correspondinginterpolation points for every joint even if one does not care so much about the exacttangential direction at some of those joints. That can be rather tedious.The\psbcurve macro of the package<strong>pst</strong>-<strong>bezier</strong> is intented to demonstrate a waytocombinetheniceproperties ofthemacros\pscurve and\ps<strong>bezier</strong>. Itprovides aneasy input format to describe ‘arbitrarily’ many interpolation points of a curve and tofix the control points at some freely selected interpolation points.Note, that <strong>pst</strong>-<strong>bezier</strong> is no final package (e.g. the automaticalcomputation of thecontrol points is not as refined as that one for the macro \pscurve).2 Installation and usage of <strong>pst</strong>-<strong>bezier</strong>.texInstallation: As prerequisites for <strong>pst</strong>-<strong>bezier</strong> you need resent working versions ofL A T E X and <strong>pst</strong>ricks. The files <strong>pst</strong>-<strong>bezier</strong>.tex and <strong>pst</strong>-<strong>bezier</strong>.sty must be somewhereinyourTE X-inputpath. Furthermore,thefile<strong>pst</strong>-<strong>bezier</strong>.pro mustbeinsomepath, where dvips can find it.Usage: As usual, load the packages <strong>pst</strong>ricks and <strong>pst</strong>-<strong>bezier</strong> in that order via the\usepackage macro.Now you are ready to use the \psbcurve macro within your document body. Thismacro is described in the next section with all its options.Whith the following simple L A T E X-source code you can test whether you have correctlyinstalled the package:1\documentclass{minimal}2\usepackage{<strong>pst</strong>ricks}3\usepackage{<strong>pst</strong>-<strong>bezier</strong>}4\begin{document}5 \begin{pspicture}(6,4)6 \psbcurve(1,2)(5,2) % Draw just onestraight line.7 \end{pspicture}8\end{document}3 The \psbcurve macroIn the most simple form you can specify any number of interpolation points as theargument of \psbcurve.


••••••••••••••••3 The\psbcurvemacro 53211\begin{pspicture}[showgrid=true](5,3)2 \psbcurve(1,1)(2,2)(3,1)(4,2)3\end{pspicture}00 1 2 3 4 5As usual, options can be specified within brackets.3211\begin{pspicture}[showgrid=true](5,3)2 \psbcurve[showpoints=true](1,1)(2,2)(3,1)(4,2)3\end{pspicture}00 1 2 3 4 5As youcansee intheabove example, theshowpoints feature works(partially) with\psbcurve.The next figure shows again the curve from the first example. This time labels areadded to the points (this is just for the following description, it is not a feature of\psbcurve).3210#» p 0 = #» l 1#» r 1#» p 1#» l 2#» r 2#» p 2#» l 30 1 2 3 4 52 \psbcurve[showpoints=true](1,1)(2,2)(3,1)(4,2)3 \uput[-90](1,1){$\vec{p}_{0}=\vec{l1\begin{pspicture}[showgrid=true](5,3)#» r 3 = #» }_{1}$}p 34 \uput[90](1.5,2){$\vec{r}_{1}$}5 \uput[90](2,2){$\vec{p}_{1}$}6 \uput[90](2.5,2){$\vec{l}_{2}$}7 \uput[-90](2.5,1){$\vec{r}_{2}$}8 \uput[-90](3,1){$\vec{p}_{2}$}9 \uput[-90](3.5,1){$\vec{l}_{3}$}10 \uput[90](4,2){$\vec{r}_{3}=\vec{p}_{3}$}11\end{pspicture}The points labeled with #» p k (k = 0,... ,3) are the interpolation points, these oneslabelledwith #» l 1 ,... , #» l 3 ,andtheseoneslabelled with #» r 1 ,... , #» r 3 aretheleftandrightcontrol points, respectively.Betweeneachconsecutivepair #» p k−1 , #» p k ofinterpolationpointsthe\psbcurvemacrodraws a cubic Bezier spline. The control points #» l k and #» r k determine the tangentialdirection of the <strong>bezier</strong> spline at the interpolation points. More exactly, the <strong>bezier</strong>spline from #» p k−1 to #» p k is tangent to the vector #» l k − #» p k−1 at the point #» p k−1 andtantengial to the vektor #» r k − #» p k at the point #» p k .


••••••••••••••••••••3 The\psbcurvemacro 6Without any optional modifier arguments (described later in this text) the controlpoints are computed automatically from the interpolation points by the formulas 1#» l 1 = #» p 0#» l k = t k ( #» p k − #» p k−2 ) for k = 2,... ,n#» r k = t k ( #» p k−1 − #» p k+1 ) for k = 1,... ,n − 1#» r n = #» p nwhere t k (k = 1,... ,n)arerealcoefficientswhicharecalledtensionandwhichdefaultto the value bcurveTension=0.25.You can change the appearance of the curve by several modifiers. First of all youcan directly set the left and right control points via the modifiers l(x,y) and r(x,y),resp., as shown in the next two examples. The unmodified curve is drawn in thebackground in blue color.32103#» l 1#» r 31\pspicture[showgrid=true](5,3)0 1 2 3 4 52\psset{showpoints=true}3\psbcurve[linecolor=blue,linewidth=0.01](1,1)%4 (2,2)(3,1)(4,2)5\psbcurve(1,1)l(2,1)(2,2)(3,1)r(4,1)(4,2)6\uput[-90](2,1){$\vec{l}_{1}$}7\uput[-90](4,1){$\vec{r}_{3}$}8\endpspicture2\psset{showpoints=true}23\psbcurve[linecolor=blue,linewidth=0.01](1,1)%4 (2,2)(3,1)(4,2)15\psbcurve(1,1)(2,2)l(2,1)(3,1)(4,2)6\uput[-90](2,1){$\vec{l}_{2}$}07\endpspicture0 1 2 3 4 5On the right hand side the last example is shown once more without grid and withshowpoints=false . There, you see that there is a corner at the second interpolationpoint.#» l 21\pspicture[showgrid=true](5,3)1\pspicture(5,3)2\psbcurve(1,1)(2,2)l(2,1)(3,1)(4,2)3\endpspictureIf you change some left control point #» l k with the help of the L(x,y) modifier thenthe control point #» r k−1 is set symmetrically to #» l k with respect to the interpolationpoint #» p k−1 . In that way you get a smooth joint as demonstrated in the next example.1 Note that this method is very crude. To compute the curve such that the curvature is continuouswould require solving a nonlinear system of equations. That is not implementedyet.


•••••••••••••••••••••••••••••••••••••••••••••••••••••••3 The\psbcurvemacro 73210#» r 11\pspicture[showgrid=true](5,3)2\psbcurve[linecolor=blue,linewidth=0.01](1,1)%#» l 2#» p 10 1 2 3 4 53 (2,2)(3,1)(4,2)4\psset{showpoints=true}5\psbcurve(1,1)(2,2)L(2,1)(3,1)(4,2)6\uput[-90](2,1){$\vec{l}_{2}$}7\uput[0](2,2){$\vec{p}_{1}$}8\uput[0](2,3){$\vec{r}_{1}$}9\endpspictureWith the t{t} modifier you can change the tension of the automatically computedcontrol points of the current Bezier spline.31\pspicture[showgrid=true](5,3)2\psset{showpoints=true}23\psbcurve[linecolor=blue,linewidth=0.01](1,1)%14 (2,2)(3,1)(4,2)5\psbcurve(1,1)(2,2)t{0.5}(3,1)(4,2)6\endpspicture00 1 2 3 4 5As you can see from the example both control points of the current spline are affectedby the t{t} modifier. If you want to change the tension of just the left or rightcontrol point you can use the tl{t} or tr{t} modifier, respectively, as demonstratedin the following two examples.32100 1 2 3 4 51\pspicture[showgrid=true](5,3)2\psset{showpoints=true}3\psbcurve[linecolor=blue,linewidth=0.01](1,1)%4 (2,2)(3,1)(4,2)5\psbcurve(1,1)%6 (2,2)tl{0.5}(3,1)(4,2)7\endpspicture03 0 1 2 3 4 51\pspicture[showgrid=true](5,3)2\psset{showpoints=true}23\psbcurve[linecolor=blue,linewidth=0.01](1,1)%14 (2,2)(3,1)(4,2)5\psbcurve(1,1)(2,2)tr{0.5}(3,1)(4,2)6\endpspicture00 1 2 3 4 5The ts{t} modifier changes the tension of the left and right control points next tothe interpolation point which stands in front of the modifier. In the next example anegative tension value leads to a rather surprising effect.31\pspicture[showgrid=true](5,3)2\psset{showpoints=true}2• • •3\psbcurve[linecolor=blue,linewidth=0.01](1,1)%14 (2,2)(3,1)(4,2)5\psbcurve(1,1)(2,2)ts{-0.5}(3,1)(4,2)6\endpspicture


••••••••••••••••••••••••••••••••••••••••••4 Things that donot work(‘known bugs’) 8The default value of the tension canbe set with theoption bcurveTension asin thefollowing example.31\pspicture[showgrid=true](5,3)2\psset{showpoints=true}23\psbcurve[linecolor=blue,linewidth=0.01](1,1)%4 (2,2)(3,1)(4,2)15\psbcurve[bcurveTension=0.5](1,1)%6 (2,2)(3,1)(4,2)07\endpspicture0 1 2 3 4 5You can set this option also with the help of the \psset macro. It is even possibleto change the value of bcurveTension in the middle of a \psbcurve. Just use themodifier T{t} for that purpose as shown in the following example.654321• • •• • •• • •• • •1\pspicture[showgrid=true](5,6)2\psset{showpoints=true}3\psbcurve[linecolor=blue,linewidth=0.01](1,1)%4 (2,2)(3,1)(4,2)(4,4)(3,5)%5 (2,4)(1,5)6\psbcurve(1,1)(2,2)(3,1)(4,2)%7 T{0.5}(4,4)(3,5)(2,4)(1,5)8\endpspicture00 1 2 3 4 5Certainly, you can use the T{t} modifier several times in one curve. (Try it foryourself.) Thelinestyle andfillstyle options (and several more) are respected by\psbcurve as the following example shows.32100 1 2 3 4 54 Things that do not work (‘known bugs’)1\pspicture[showgrid=true](5,3)2\psbcurve[linestyle=dashed,3 linewidth=3pt,4 dash=0.5 0.2,5 fillstyle=solid,6 fillcolor=blue](1,1)(2,2)(3,1)(4,2)7\endpspictureAs already mentioned this project is something like an experiment. So, there aremany things that do not work.• new lines inside the argument list are not ignored.• Thecontrolpointsarecomputedinarathercrudeway(seeabove). Thecurvatureoption is not recognised.


References 9• If fillstyle is set to solid and showpoints=true then the fill color covers theinterpolation and control points.• arrow heads do not work.5 List of all optional arguments for <strong>pst</strong>-<strong>bezier</strong>Key Type DefaultbcurveTension ordinary 0.25References[1] Michel Goosens, Frank Mittelbach, Serbastian Rahtz, Denis Roegel, and HerbertVoß. The L A T E X Graphics Companion. Addison-Wesley Publishing Company,Reading, Mass., 2nd edition, 2007.[2] Laura E. Jacksonand Herbert Voß. Die Plot-Funktionen von <strong>pst</strong>-plot. DieT E Xnische Komödie, 2/02:27–34, June 2002.[3] Nikolai G. Kollock. PostScript richtig eingesetzt: vom Konzept zum praktischenEinsatz. IWT, Vaterstetten, 1989.[4] Herbert Voß. Die mathematischenFunktionen von Postscript. Die T E XnischeKomödie, 1/02:40–47, March 2002.[5] Herbert Voss. <strong>PSTricks</strong> Support for pdf. http://<strong>PSTricks</strong>.de/pdf/pdfoutput.phtml, 2002.[6] Herbert Voß. <strong>PSTricks</strong> – Grafik für T E X und L A T E X. DANTE/LehmannsMedia,Heidelberg/Berlin, 5. edition, 2008.[7] Herbert Voß. Mathematik mit L A T E X. DANTE/LehmannsMedia,Heidelberg/Berlin, 2009.[8] Michael Wiedmann and Peter Karp. References for T E X and Friends. http://www.miwie.org/tex-refs/, 2003.[9] Timothy Van Zandt. <strong>PSTricks</strong> - PostScript macros for Generic TeX. http://www.tug.org/application/<strong>PSTricks</strong>, 1993.


IndexbcurveTension, 6, 8curvature, 3, 8dvips, 4false, 6File<strong>pst</strong>-<strong>bezier</strong>.pro, 4<strong>pst</strong>-<strong>bezier</strong>.sty, 4<strong>pst</strong>-<strong>bezier</strong>.tex, 4fillstyle, 9KeywordbcurveTension, 6, 8curvature, 3, 8fillstyle, 9showpoints, 5, 6, 9solid, 9L, 6l, 6Macro\psbcurve, 4, 5, 8\ps<strong>bezier</strong>, 3, 4\pscurve, 3, 4\psset, 8\usepackage, 4showpoints, 5, 6, 9solid, 9spline, 3SyntaxL, 6l, 6r, 6T, 8t, 7tl, 7tr, 7ts, 7T, 8t, 7tl, 7tr, 7true, 9ts, 7\usepackage, 4Valuefalse, 6true, 9Package<strong>pst</strong>-<strong>bezier</strong>, 4<strong>pst</strong>ricks, 3, 4Programdvips, 4\psbcurve, 4, 5, 8\ps<strong>bezier</strong>, 3, 4\pscurve, 3, 4\psset, 8<strong>pst</strong>-<strong>bezier</strong>, 4<strong>pst</strong>-<strong>bezier</strong>.pro, 4<strong>pst</strong>-<strong>bezier</strong>.sty, 4<strong>pst</strong>-<strong>bezier</strong>.tex, 4<strong>pst</strong>ricks, 3, 4r, 610

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!