Graphics, Figures & TablesPSTricks | Code Optimizations

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | Code Optimizations

Post by svend_tveskaeg »

Hi all.

Consider the following MWE:

Code: Select all

\documentclass{article}

\usepackage{pstricks-add}

\begin{document}

\begin{figure}
\def\radius{5}
\pstFPmul\maximum{2}{\radius}
 \centering
 \psset{unit=0.8cm}
  \begin{pspicture}(\maximum,\maximum)
   \pnode(!\radius\space \radius\space){S}
   \uput[315](S){$S$}
   \pscircle(S){\radius}
   \multido{\iA=1+2,\iB=2+2,\rA=0+270,\rC=225+270,\rB=0+270,\rD=180+270}{4}{%
     \psRelNode[angle=\rA](S)(0,0){1}{P\iA}
     \uput[\rC](P\iA){$P_{\iA}$}
     \psRelNode[angle=\rB](S)(!0 \radius\space){1}{P\iB}
     \uput[\rD](P\iB){$P_{\iB}$}
   }
   \pspolygon(P1)(P3)(P5)(P7)
   \pspolygon(P2)(P4)(P6)(P8)
  \psset{linestyle=dotted}
   \pcline(P2)(P6)
   \pcline(P4)(P8)
  \end{pspicture}
\end{figure}

\end{document}
I have a feeling that the drawing can be created with more elegant or efficient code, especially the \multido part.

If anyone can create the drawing using "better" code, please let me know.

Thank you in advance!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | Code Optimizations

Post by CrazyHorse »

svend_tveskaeg wrote: I have a feeling that the drawing can be created with more elegant or efficient code, especially the \multido part.
It makes no sense to put objects which are completely symmetrical to one point not to that central point:

Code: Select all

\psset{unit=0.8cm}
  \begin{pspicture}(-\radius,-\radius)(\radius,\radius)
   \uput[315](0,0){$S$}\psdot(0,0)
   \pscircle(0,0){\radius}
   \psframe(!-\radius\space dup)(!\radius\space dup)
   \rput{45}(0,0){\psframe(!-\radius\space 2 sqrt div dup)(!\radius\space 2 sqrt div dup)}
   \multido{\iA=180+-90,\iB=2+2,
            \iC=225+-90,\iD=1+2}{4}{%
      \uput[\iA](\radius;\iA){$P_{\iB}$}
      \uput[\iC](!\radius\space 2 sqrt mul \iC\space PtoC){$P_{\iD}$}}
  \psline[linestyle=dotted](0,-\radius)(0,\radius)
  \psline[linestyle=dotted](-\radius,0)(\radius,0)
  \end{pspicture}
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | Code Optimizations

Post by svend_tveskaeg »

CrazyHorse wrote:It makes no sense to put objects which are completely symmetrical to one point not to that central point.
Good point.

Thank you very much for helping me.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply