Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to draw a \pspolygon with arbitrary arguments

231 views
Skip to first unread message

chrishunter

unread,
Apr 4, 2010, 12:48:35 PM4/4/10
to
Hi,


I need in a (La)TeX document a command that using PSTricks draws a
picture with a background and on top of that a ten-pointed star where
the distances from center to each of the points are arbitrary and
given in the argument to the command.
Something like this

...
\newcommand{\recoverystar}[1]{

% do something with #1 and put it in *something*

\begin{pspicture}(-10,-10)(10,10)
% do something

\SpecialCoor
\degrees[10]
\pspolygon *something*

\end{pspicture}
}

\recoverystar(3, 6, 9, 2, 5, 8, 1, 4, 7, 10)

witch should draw the background and on top of that a star like

\pspolygon(3, 0)(2, 0.5)(6, 1)(2, 1.5)(9, 2) ... (5, 3) ... (7, 8) ...
(10, 9)(2, 9.5)


Chris

Herbert Voss

unread,
Apr 4, 2010, 3:22:55 PM4/4/10
to Graphics with PSTricks
Am 04.04.2010 18:48, schrieb chrishunter:

> \recoverystar(3, 6, 9, 2, 5, 8, 1, 4, 7, 10)
>
> witch should draw the background and on top of that a star like
>
> \pspolygon(3, 0)(2, 0.5)(6, 1)(2, 1.5)(9, 2) ... (5, 3) ... (7, 8) ...
> (10, 9)(2, 9.5)

\documentclass{minimal}
\usepackage{pstricks}

\makeatletter
\def\recoverystar(#1){\expandafter\rstar@i#1,,\@nil}
\def\rstar@i#1,#2,,\@nil{%
\def\St@rt{#1}%
\rstar@ii#2}
\def\rstar@ii#1,#2,#3,#4,#5,#6,#7,#8,#9{%
\SpecialCoor%
\degrees[10]%
\begin{pspicture}(-10,-10)(10,10)
\pspolygon(\St@rt;0)(2;0.5)(#1;1)(2;1.5)(#2;2)(2;2.5)(#3;3)(2;3.5)%
(#4;4)(2;4.5)(#5;5)(2;5.5)(#6;6)(2;6.5)(#7;7)(2;7.5)%
(#8;8)(2;8.5)(#9;9)(2;9.5)
\end{pspicture}%
}
\makeatother
\begin{document}

\recoverystar(3, 6, 9, 2, 5, 8, 1, 4, 7, 10)

\end{document}

Herbert

chrishunter

unread,
Apr 5, 2010, 1:02:23 AM4/5/10
to
Thank you, Herbert, Thanks a lot. That will work, and your answer
helps a lot

But what I didn't write is that I also wish to make two other
commands: One which takes two sets og arguments like

\recoverystarFilled(...)(...)

and then makes two stars with filling in between.

And one which takes four sets making two stars with filling in between
and two other with filling in between on top of those.

Can I do that and how?


Chris


Herbert Voss

unread,
Apr 5, 2010, 3:42:41 AM4/5/10
to
Am 05.04.2010 07:02, schrieb chrishunter:

> But what I didn't write is that I also wish to make two other
> commands: One which takes two sets og arguments like
>
> \recoverystarFilled(...)(...)
>
> and then makes two stars with filling in between.
>
> And one which takes four sets making two stars with filling in between
> and two other with filling in between on top of those.
>
> Can I do that and how?

\documentclass{minimal}
\usepackage{pstricks}

\makeatletter
\define@key[psset]{}{innerRadius}[1]{\pst@getlength{#1}\psk@InnerRadius}
\psset{innerRadius=2cm}
\def\recoverystar{\pst@object{recoverystar}}
\def\recoverystar@i(#1){%
\begin@ClosedObj
\addto@pscode{
/coor [#1] def
coor length /no ED
/angleunit { 360 no div mul } def
/radius \psk@InnerRadius\space def
coor 0 get \pst@number\psrunit mul 0 moveto
radius 0.5 angleunit PtoC lineto
1 1 no 1 sub {
/relAngle ED
coor relAngle get \pst@number\psrunit mul relAngle angleunit PtoC
lineto
radius relAngle 0.5 add angleunit PtoC lineto
} for
closepath
}
\end@ClosedObj%
}
\makeatother

\begin{document}

\psset{unit=0.5}
\begin{pspicture}(-10,-10)(10,10)
\recoverystar(3 6 9 2 5 8 1 4 7 10)
\recoverystar[innerRadius=1.5,fillcolor=red!30,fillstyle=solid,
linecolor=blue](5 4 8 10 9 6 7 10)
\end{pspicture}

\end{document}


Herbert

chrishunter

unread,
Apr 5, 2010, 4:53:36 AM4/5/10
to
Thanks again, Herbert.

I've tried it (copy and paste the document you wrote from
\documentclass{minimal} till \end{document}) and got the following
error massage:

...
(/usr/share/texmf/tex/generic/pstricks/pstricks.tex
`PSTricks' v1.26 <2008/07/31> (tvz)
(/usr/share/texmf/tex/generic/pstricks/pstricks.con))
(/usr/share/texmf/tex/latex/xcolor/xcolor.sty
(/usr/lib/texmf/tex/latex/config/color.cfg)
(/usr/share/texmf/tex/latex/graphics/dvips.def)))
! Undefined control sequence.
l.5 \define@key


[psset]{}{innerRadius}[1]
{\pst@getlength{#1}\psk@InnerRadius}

?

I suppose the fault is in the LaTeX or PSTricks at my machine. But how
do I fix it?


Chris

Message has been deleted
Message has been deleted

Herbert Voss

unread,
Apr 5, 2010, 5:50:53 AM4/5/10
to
Am 05.04.2010 10:53, schrieb chrishunter:

> I've tried it (copy and paste the document you wrote from
> \documentclass{minimal} till \end{document}) and got the following
> error massage:

> ! Undefined control sequence.
> l.5 \define@key


> [psset]{}{innerRadius}[1]
> {\pst@getlength{#1}\psk@InnerRadius}

> ?
>
> I suppose the fault is in the LaTeX or PSTricks at my machine. But how
> do I fix it?

your system is not up to date. Try

\documentclass{minimal}
\usepackage{pstricks}
\usepackage{pst-xkey}
...


Herbert

chrishunter

unread,
Apr 5, 2010, 7:02:28 AM4/5/10
to
Thanks a lot, Herbert. Now i works just fine.

chrishunter

unread,
Apr 6, 2010, 12:33:29 PM4/6/10
to
Sorry to bother you again.

But, how could I make a command that takes two sets of arguments
drawing two stars with filling in between?

Something where

recoverystarfilled(5 6 ... 7)(7 8 ... 10)

would draw recoverystar(5 6 ... 7) and recoverystar(7 8 ... 10) and
make the filling between those two stars.


Chris

Herbert Voss

unread,
Apr 6, 2010, 1:37:25 PM4/6/10
to

have a look at the clipping macro of PSTricks.
Examples are also available at http://PSTricks.tug.org

Herbert

chrishunter

unread,
Apr 11, 2010, 2:30:22 AM4/11/10
to
> \psset{unit=0.5}
> \begin{pspicture}(-10,-10)(10,10)
> \recoverystar(3 6 9 2 5 8 1 4 7 10)
> \recoverystar[innerRadius=1.5,fillcolor=red!30,fillstyle=solid,
>     linecolor=blue](5 4 8 10 9 6 7 10)
> \end{pspicture}

One problem:
The second star is centered a few millimeters to the right compared to
the first, and a third star centers the same length to the right of
the center of the second one and so on.

I have searched and searched in the code for something that makes the
stars move to the right but with on luck.

Any ideas, anyone?

Chris

Herbert Voss

unread,
Apr 11, 2010, 3:45:20 AM4/11/10
to

a trailing space:

....
}% <=== the % was missing ====
\end@ClosedObj%
...

Herbert

0 new messages