| 1 |
%% $Id: pst-poly.tex 332 2010-05-28 18:45:07Z herbert $ |
| 2 |
%% |
| 3 |
%% This is file `pst-poly.tex', |
| 4 |
%% |
| 5 |
%% IMPORTANT NOTICE: |
| 6 |
%% |
| 7 |
%% (C) |
| 8 |
%% Denis Girou (CNRS/IDRIS - France) <[email protected]> |
| 9 |
%% Herbert Voss <[email protected]> |
| 10 |
%% |
| 11 |
%% This program can be redistributed and/or modified under the terms |
| 12 |
%% of the LaTeX Project Public License Distributed from CTAN archives |
| 13 |
%% in directory macros/latex/base/lppl.txt. |
| 14 |
%% |
| 15 |
%% DESCRIPTION: |
| 16 |
%% `pst-poly' is a PSTricks package to draw easily various kinds of regular |
| 17 |
%% or non regular polygons, with various customizations. |
| 18 |
%% |
| 19 |
% |
| 20 |
\csname PSTPolygonLoaded\endcsname |
| 21 |
\let\PSTPolygonLoaded\endinput |
| 22 |
\ifx\PSTricksLoaded\endinput\else\input pstricks.tex\fi |
| 23 |
\ifx\PSTnodesLoaded\endinput\else\input pst-node.tex\fi |
| 24 |
\ifx\MultidoLoaded\endinput\else \input multido.tex\fi |
| 25 |
\ifx\PSTXKeyLoaded\endinput\else \input pst-xkey \fi |
| 26 |
% |
| 27 |
\def\fileversion{1.63} |
| 28 |
\def\filedate{2014/08/28} |
| 29 |
\message{`PST-Polygon' v\fileversion, \filedate\space (DG/hv)} |
| 30 |
% |
| 31 |
\edef\PstAtCode{\the\catcode`\@} |
| 32 |
\catcode`\@=11\relax |
| 33 |
\pst@addfams{pst-poly} |
| 34 |
\define@boolkey[psset]{pst-poly}[Pst@]{PstPicture}[true]{} |
| 35 |
\define@key[psset]{pst-poly}{PolyRotation}[0]{\def\PstPoly@Rotation{#1}} |
| 36 |
\define@key[psset]{pst-poly}{PolyNbSides}[5]{\pst@getint{#1}{\PstPoly@NbSides}% |
| 37 |
\ifnum\PstPoly@NbSides<3 |
| 38 |
\@pstrickserr{PolyNbSides must be greater than 2 |
| 39 |
(and not `\PstPoly@NbSides')}{\@eha}% |
| 40 |
\fi% |
| 41 |
\ifnum\PstPoly@NbSides>200 |
| 42 |
\@pstrickserr{PolyNbSides must be less than 201 |
| 43 |
(and not `\PstPoly@NbSides')}{\@eha}% |
| 44 |
\fi} |
| 45 |
\define@key[psset]{pst-poly}{PolyOffset}[1]{\pst@getint{#1}{\PstPoly@Offset}% |
| 46 |
\ifnum\PstPoly@Offset<1 |
| 47 |
\@pstrickserr{PolyOffset must be greater than 0 |
| 48 |
(and not `\PstPoly@Offset')}{\@eha}% |
| 49 |
\fi} |
| 50 |
\newdimen\PstPoly@IntermediatePointDim |
| 51 |
\define@key[psset]{pst-poly}{PolyIntermediatePoint}[]{\def\PstPoly@IntermediatePoint{#1}} |
| 52 |
\define@key[psset]{pst-poly}{PolyName}[]{\def\PstPoly@Name{#1}} |
| 53 |
\define@boolkey[psset]{pst-poly}[Pst@]{PolyCurves}[true]{} |
| 54 |
\define@boolkey[psset]{pst-poly}[Pst@]{PolyEpicycloid}[true]{} |
| 55 |
\psset{% |
| 56 |
PstPicture=true,PolyRotation=0,PolyNbSides=5,PolyOffset=1, |
| 57 |
PolyIntermediatePoint=,PolyName=,PolyCurves=false,PolyEpicycloid=false} |
| 58 |
% |
| 59 |
\SpecialCoor |
| 60 |
% |
| 61 |
\def\PstPolygon{\pst@object{PstPolygon}} |
| 62 |
\def\PstPolygon@i{{% |
| 63 |
\use@par |
| 64 |
\if@star\solid@star\fi |
| 65 |
\ifodd\PstPoly@Offset\def\PstPoly@Decimal{.5}\else\def\PstPoly@Decimal{}\fi |
| 66 |
\ifPst@PstPicture\pspicture(-1,-1)(1,1)\fi |
| 67 |
\rput{\PstPoly@Rotation}(0,0){% |
| 68 |
\degrees[\PstPoly@NbSides]% |
| 69 |
\NormalCoor |
| 70 |
\pssetlength{\PstPoly@IntermediatePointDim}{\PstPoly@IntermediatePoint}% |
| 71 |
\SpecialCoor |
| 72 |
\ifx\PstPoly@Name\@empty |
| 73 |
\else |
| 74 |
\pnode(0,0){\PstPoly@Name 0}% |
| 75 |
\ifnum\psxunit=\psyunit |
| 76 |
\def\PstPoly@Node{\pnode(1;\i)}% |
| 77 |
\else |
| 78 |
\def\PstPoly@Node{% |
| 79 |
\pnode(! \i\space 360 \PstPoly@NbSides\space div mul cos |
| 80 |
\i\space 360 \PstPoly@NbSides\space div mul sin)}% |
| 81 |
\fi |
| 82 |
\multido{\i=0+1}{\PstPoly@NbSides}{% |
| 83 |
\PstPoly@Node{\PstPoly@Name\the\multidocount}}% |
| 84 |
\fi |
| 85 |
\pscustom{ |
| 86 |
\ifPst@PolyEpicycloid |
| 87 |
\pst@cnta=\PstPoly@NbSides |
| 88 |
\divide\pst@cnta\tw@ |
| 89 |
\multido{\i=0+1}{\PstPoly@NbSides}{% |
| 90 |
\moveto(1;\i) |
| 91 |
\lineto(1;\the\pst@cnta) |
| 92 |
\advance\pst@cnta\PstPoly@Offset}% |
| 93 |
\else |
| 94 |
\ifnum\psxunit=\psyunit \moveto(1,0)\else\moveto(! 1 0)\fi |
| 95 |
\ifx\PstPoly@IntermediatePoint\@empty |
| 96 |
\ifnum\psxunit=\psyunit |
| 97 |
\def\PstPoly@Junction{\lineto(1;\i)}% |
| 98 |
\else |
| 99 |
\def\PstPoly@Junction{\lineto |
| 100 |
(! \i\space 360 \PstPoly@NbSides\space div mul cos |
| 101 |
\i\space 360 \PstPoly@NbSides\space div mul sin)}% |
| 102 |
\fi |
| 103 |
\multido{\i=\PstPoly@Offset+\PstPoly@Offset}{\PstPoly@NbSides}{\PstPoly@Junction}% |
| 104 |
\else |
| 105 |
\ifPst@PolyCurves\let\PstPoly@JunctionType\pscurve\else\let\PstPoly@JunctionType\psline\fi |
| 106 |
\ifnum\psxunit=\psyunit |
| 107 |
\def\PstPoly@Junction{\PstPoly@JunctionType% |
| 108 |
(\PstPoly@IntermediatePointDim;\the\pst@cnta\PstPoly@Decimal)(1;\i)}% |
| 109 |
\else |
| 110 |
\def\PstPoly@Junction{\PstPoly@JunctionType% |
| 111 |
(! \PstPoly@IntermediatePoint\space \the\pst@cnta\PstPoly@Decimal\space 360 |
| 112 |
\PstPoly@NbSides\space div mul cos mul |
| 113 |
\PstPoly@IntermediatePoint\space \the\pst@cnta\PstPoly@Decimal\space 360 |
| 114 |
\PstPoly@NbSides\space div mul sin mul) |
| 115 |
(! \i\space 360 \PstPoly@NbSides\space div mul cos \i\space 360 \PstPoly@NbSides\space div mul sin)}% |
| 116 |
\fi |
| 117 |
\pst@cnta=\PstPoly@Offset |
| 118 |
\divide\pst@cnta\tw@ |
| 119 |
\multido{\i=\PstPoly@Offset+\PstPoly@Offset}{\PstPoly@NbSides}{% |
| 120 |
\PstPoly@Junction |
| 121 |
\advance\pst@cnta\PstPoly@Offset}% |
| 122 |
\fi |
| 123 |
\fi}% |
| 124 |
\ifx\PstPolygonNode\@undefined |
| 125 |
\else\multido{\INode=\z@+\PstPoly@Offset}{\PstPoly@NbSides}{\PstPolygonNode}\fi}% |
| 126 |
\ifPst@PstPicture\endpspicture\fi |
| 127 |
}} |
| 128 |
% |
| 129 |
\def\PstTriangle{\pst@object{PstTriangle}} |
| 130 |
\def\PstTriangle@i{{% |
| 131 |
\addto@par{PolyNbSides=3,PolyRotation=90}% For triangle (360/3*(3/4)) |
| 132 |
\use@par% |
| 133 |
\if@star\solid@star\fi |
| 134 |
\PstPolygon}} |
| 135 |
% |
| 136 |
\def\PstSquare{\pst@object{PstSquare}} |
| 137 |
\def\PstSquare@i{{% |
| 138 |
\addto@par{PolyNbSides=4,PolyRotation=45}% For square (360/4/2) |
| 139 |
\use@par% |
| 140 |
\if@star\solid@star\fi |
| 141 |
\PstPolygon}} |
| 142 |
% |
| 143 |
\def\PstPentagon{\pst@object{PstPentagon}} |
| 144 |
\def\PstPentagon@i{{% |
| 145 |
\addto@par{PolyNbSides=5,PolyRotation=18}% For pentagon (360/5/4) |
| 146 |
\use@par |
| 147 |
\if@star\solid@star\fi |
| 148 |
\PstPolygon}} |
| 149 |
% |
| 150 |
\def\PstHexagon{\pst@object{PstHexagon}} |
| 151 |
\def\PstHexagon@i{{% |
| 152 |
\addto@par{PolyNbSides=6}% |
| 153 |
\use@par% |
| 154 |
\if@star\solid@star\fi |
| 155 |
\PstPolygon}} |
| 156 |
% |
| 157 |
\def\PstHeptagon{\pst@object{PstHeptagon}} |
| 158 |
\def\PstHeptagon@i{{% |
| 159 |
\addto@par{PolyNbSides=7,PolyRotation=38.57}% For heptagon (360/7*(3/4)) |
| 160 |
\use@par% |
| 161 |
\if@star\solid@star\fi |
| 162 |
\PstPolygon}} |
| 163 |
% |
| 164 |
\def\PstOctogon{\pst@object{PstOctogon}} |
| 165 |
\def\PstOctogon@i{{% |
| 166 |
\addto@par{PolyNbSides=8,PolyRotation=22.5}% For octogon (360/8/2) |
| 167 |
\use@par% |
| 168 |
\if@star\solid@star\fi |
| 169 |
\PstPolygon}} |
| 170 |
% |
| 171 |
\def\PstNonagon{\pst@object{PstNonagon}} |
| 172 |
\def\PstNonagon@i{{% |
| 173 |
\addto@par{PolyNbSides=9,PolyRotation=10}% For nonagon (360/9/4) |
| 174 |
\use@par% |
| 175 |
\if@star\solid@star\fi |
| 176 |
\PstPolygon}} |
| 177 |
% |
| 178 |
\def\PstDecagon{\pst@object{PstDecagon}} |
| 179 |
\def\PstDecagon@i{{% |
| 180 |
\addto@par{PolyNbSides=10}% |
| 181 |
\use@par% |
| 182 |
\if@star\solid@star\fi |
| 183 |
\PstPolygon}} |
| 184 |
% |
| 185 |
\def\PstDodecagon{\pst@object{PstDodecagon}} |
| 186 |
\def\PstDodecagon@i{{% |
| 187 |
\addto@par{PolyNbSides=12,PolyRotation=15}% For dodecagon (360/12/2) |
| 188 |
\use@par% |
| 189 |
\if@star\solid@star\fi |
| 190 |
\PstPolygon}} |
| 191 |
% |
| 192 |
\def\PstStarFiveLines{\pst@object{PstStarFiveLines}} |
| 193 |
\def\PstStarFiveLines@i{{% |
| 194 |
\addto@par{PolyOffset=2,PolyRotation=18}% |
| 195 |
\use@par% |
| 196 |
\if@star\solid@star\fi |
| 197 |
\PstPolygon}} |
| 198 |
% |
| 199 |
\def\PstStarFive{\pst@object{PstStarFive}} |
| 200 |
\def\PstStarFive@i{{% |
| 201 |
\addto@par{PolyIntermediatePoint=0.38,PolyRotation=18}% |
| 202 |
\use@par% |
| 203 |
\if@star\solid@star\fi |
| 204 |
\PstPolygon}} |
| 205 |
% |
| 206 |
% Aspecial version for pst-poly |
| 207 |
\def\pst@polypyth#1#2#3{\ifdim#1>#2\pst@@polypyth#1#2#3\else\pst@@polypyth#2#1#3\fi} |
| 208 |
\def\pst@@polypyth#1#2#3{% |
| 209 |
\ifdim4#1>9#2 #3=#1\advance#3 .2122#2% |
| 210 |
\else#3=.8384#1\advance#3 .5758#2\fi} |
| 211 |
% |
| 212 |
\def\pspolygonbox{\pst@object{pspolygonbox}}% voss 2004-11-20 |
| 213 |
\def\pspolygonbox@i{\pst@makebox\pspolygonbox@ii} |
| 214 |
\def\pspolygonbox@ii{% |
| 215 |
\begingroup% |
| 216 |
\addbefore@par{boxsep=true}% |
| 217 |
\pst@useboxpar% |
| 218 |
\pst@dima=\pslinewidth% |
| 219 |
\ifpsdoubleline% |
| 220 |
\advance\pst@dima by \psdoublesep\pslinewidth% |
| 221 |
\advance\pst@dima by \pslinewidth% |
| 222 |
\fi% |
| 223 |
\advance\pst@dima by \psframesep% |
| 224 |
\pst@dimc=\wd\pst@hbox% |
| 225 |
\pst@dimp=\pst@dimc |
| 226 |
\advance\pst@dimp by 2\pst@dima |
| 227 |
\pst@dimb=\dp\pst@hbox |
| 228 |
\pst@dimo=\pst@dimb% |
| 229 |
\pst@dimd=\ht\pst@hbox |
| 230 |
\advance\pst@dimo by \pst@dimd% totalheight |
| 231 |
\pst@polypyth\pst@dimp\pst@dimo\pst@dimm |
| 232 |
\global\divide\pst@dimm by 2% Radius |
| 233 |
\setbox\pst@hbox=\hbox{% |
| 234 |
\ifpsboxsep\kern\pst@dima\fi% left side |
| 235 |
\begin@ClosedObj% |
| 236 |
\addto@pscode{ |
| 237 |
/framesep \pst@number\pst@dima def |
| 238 |
/boxdepth \pst@number\pst@dimb framesep add def |
| 239 |
/boxheight0 \pst@number\pst@dimd def |
| 240 |
/boxheight boxheight0 framesep add def |
| 241 |
/boxwidth \pst@number\pst@dimc def |
| 242 |
/radius \pst@number\pst@dimm def |
| 243 |
/order \PstPoly@NbSides\space def |
| 244 |
/dAlpha 360 order div def |
| 245 |
/alpha \PstPoly@Rotation\space def |
| 246 |
\pst@cp |
| 247 |
\tx@polygonB |
| 248 |
\psline@iii |
| 249 |
\tx@Polygon |
| 250 |
}% |
| 251 |
\def\pst@linetype{1}% |
| 252 |
\showpointsfalse% |
| 253 |
\end@ClosedObj% |
| 254 |
\box\pst@hbox% |
| 255 |
\ifpsboxsep\kern\pst@dima\fi%% right side |
| 256 |
}% |
| 257 |
\ifpsboxsep% |
| 258 |
\pst@dimn=-.5\pst@dimo\advance\pst@dimn by \pst@dimb% |
| 259 |
\advance\pst@dimn by 0.809\pst@dimm% |
| 260 |
\dp\pst@hbox=\pst@dimn% |
| 261 |
\pst@dimn=\pst@dimm\advance\pst@dimn by 0.5\pst@dimo% |
| 262 |
\advance\pst@dimn by -\pst@dimb% |
| 263 |
\ht\pst@hbox=\pst@dimn\fi% |
| 264 |
\leavevmode% |
| 265 |
\box\pst@hbox% |
| 266 |
\endgroup% |
| 267 |
\ignorespaces} |
| 268 |
% |
| 269 |
\pst@def{polygonB}<{% |
| 270 |
/x1 framesep neg def |
| 271 |
/x2 boxwidth framesep add def |
| 272 |
/y1 boxdepth framesep add neg def |
| 273 |
/y2 boxheight framesep add def |
| 274 |
x2 x1 add 2 div y2 y1 add 2 div translate |
| 275 |
[ |
| 276 |
alpha cos radius mul |
| 277 |
alpha sin radius mul |
| 278 |
order { /alpha alpha dAlpha add def |
| 279 |
radius alpha cos mul |
| 280 |
radius alpha sin mul |
| 281 |
} repeat |
| 282 |
}> |
| 283 |
% |
| 284 |
\catcode`\@=\PstAtCode\relax |
| 285 |
\endinput |
| 286 |
%% |
| 287 |
%% End of file `pst-poly.tex'. |