2

This is a minimal workable code of my code

\documentclass{article}
\usepackage{pstricks-add,pst-plot}
\usepackage[paperheight=16cm,paperwidth=21cm,margin=0pt]{geometry}

\pagestyle{empty}

\def\prism{\pspolygon[](0.62,0.62)(4.62,0.62)(4,0)(0,0)} % prism

\begin{document}

\psset{algebraic,xunit=1cm,yunit=1cm}
\noindent
\begin{pspicture}(0,0)(21,16)
\uput[r](0.85,1.2){
\rput(8,10){\psrotate(0,0){0}{\prism}}
}
\end{pspicture}

\end{document}

As you can see, I'm defining a pspolygon before the \begin{document} and then I'm calling it inside the pspicture with a rput command. This allows me to draw the polygon only once and then use it as many times as I want in the picture. I will have to place several of them in my code, some rotated, some translated and the way my code is now I can do it without problem.

The problem is that I want some of the polygons to be larger than others. How can I rescale an object like this \prism inside the pspicture? If, for example, I would like the polygon to be half its size, I'd like a command like

\rput[scale=0.5](8,10){\psrotate(0,0){0}{\prism}}

Can you help me with this?

Thank you.

2 Answers 2

1

You can use \psscalebox{<scale>}{<stuff>} to scale <stuff> to the <scale> of your choice:

enter image description here

\documentclass{article}

\usepackage{pstricks-add}

\def\prism{\pspolygon(0.62,0.62)(4.62,0.62)(4,0)(0,0)} % prism

\begin{document}

\psset{algebraic,unit=1cm}

\begin{pspicture}(0,0)(5,5)
  \rput(2,2){\psrotate(0,0){0}{\prism}}
  \rput(2,4){\psscalebox{0.5}{\psrotate(0,0){30}{\prism}}}
  \rput(4,4){\psset{unit=5mm}\psrotate(0,0){30}{\prism}}
\end{pspicture}

\end{document}

Note the difference between scaling something (which also scales the line width) and adjusting the unit to be 50% of the original unit (maintaining the same line width).


You could define your own macro for adjusting the content. Below I've used xkeyval to define a number of keys for a single macro called \psaction[<options>]{<object>}:

\usepackage{xkeyval}

\makeatletter
\define@cmdkey{psaction}[psaction@]{orotate}{}
\define@cmdkey{psaction}[psaction@]{rotangle}{}
\define@cmdkey{psaction}[psaction@]{scale}{}
\define@cmdkey{psaction}[psaction@]{put}{}
\newcommand{\psaction}[2][]{%
  \setkeys{psaction}{%
    orotate={(0,0)}, % Default origin of rotation
    rotangle=0, % Default angle of rotation
    scale=1, % Default scale factor
    put={(0,0)}, % Default location for \rput
    #1 % Local modifications
  }%
  \begingroup
  \gdef\psaction@object{#2}%
  \edef\x{\endgroup
    \noexpand\rput\psaction@put{%
      \noexpand\psscalebox{\psaction@scale}{%
        \noexpand\psrotate\psaction@orotate{\psaction@rotangle}{%
          \noexpand\psaction@object}}}}\x
}
\makeatother

For example, you could use

\begin{pspicture}(0,0)(5,5)
  % Similar to \rput(2,2){\psrotate(0,0){0}{\prism}}:
  \psaction[put={(2,2)}]{\prism}
  % Similar to \rput(2,4){\psscalebox{0.5}{\psrotate(0,0){30}{\prism}}}:
  \psaction[put={(2,4)},scale=0.5,rotangle=30]{\prism}
\end{pspicture}
0

Use the optional argument unit=...

\documentclass{article}
\usepackage{pstricks-add}
\newcommand\prism[1][]{%
    \pspolygon[#1](0.62,0.62)(4.62,0.62)(4,0)(0,0)} % prism    
\begin{document}

\begin{pspicture}[showgrid](7,6)
\rput(1,1){\prism}
\rput{30}(2,4){\prism[unit=0.5]}
\rput{-30}(4,4){%
     \prism[unit=6mm,linecolor=red,fillstyle=solid,fillcolor=red!40]}
\end{pspicture}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .