Graphics, Figures & TablesPSTricks | Draw a Brick

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 | Draw a Brick

Post by svend_tveskaeg »

Hi all.

Consider the following MWE (inspired by this topic) where I try to draw a brick:

Code: Select all

\documentclass{article}

\usepackage{auto-pst-pdf,pst-solides3d,pstricks-add}
%\usepackage{siunitx}
\definecolor{nicered}{rgb}{0.796,0.255,0.329}

\begin{document}

\begin{figure}
 \centering
 \psset{unit=5cm,viewpoint=10 -30 15 rtp2xyz,Decran=9}
  \begin{pspicture}[solidmemory](-5,-5)(6,12)
   \psSolid[object=parallelepiped,a=2.28,b=1.08,c=0.54,RotZ=30,fillcolor=nicered,name=brick,action=draw*](0 0 0)
   \multido{\iA=0+1}{8}{%
     \psSolid[object=point,definition=solidgetsommet,args=brick \iA,action=none,name=P\iA]
     \uput[90](P\iA){$P_{\iA}$}
   }
%  \psset{offset=12pt,nrot=:U}
   \psSolid[object=line,linecolor=green,args=P0 P4]
%   \ncput*{$h = \SI{5.4}{\cm}$}
   \psSolid[object=line,linecolor=green,args=P4 P7]
%   \ncput*{$b = \SI{10.8}{\cm}$}
   \psSolid[object=line,linecolor=green,args=P7 P6]
%   \ncput*{$l = \SI{22.8}{\cm}$}
  \end{pspicture}
\end{figure}

\end{document}
I am trying to label the green sides (which should not be green in the finale drawing). I would like to label them as in the example at the bottom of page 71 in the pstricks manual, i.e., with offset and lines with arrows as |-|, but (of course) \ncput* is not working. Furthermore, I would like to put a node $P_i$ at every corner of the brick, but \uput seems to have no effect here.

How do I do these things?

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 | Draw a Brick

Post by CrazyHorse »

svend_tveskaeg wrote: Consider the following MWE (inspired by this topic) where I try to draw a brick:


I am trying to label the green sides (which should not be green in the finale drawing). I would like to label them as in the example at the bottom of page 71 in the pstricks manual, i.e., with offset and lines with arrows as |-|, but (of course) \ncput* is not working. Furthermore, I would like to put a node $P_i$ at every corner of the brick, but \uput seems to have no effect here.
you cannot mix 2d and 3d functions. Drawing in 3d with perspective view and hidden lines and surfaces is a bit more complecated as the trivial 2d stuff.

First the box:

Code: Select all

\documentclass{article}
\usepackage{pst-solides3d}
\begin{document}

 \psset{viewpoint=10 -30 15 rtp2xyz,Decran=30}
  \begin{pspicture}[solidmemory](-5,-5)(6,12)
   \psSolid[object=parallelepiped,a=2.28,b=1.08,c=0.54,RotZ=30,
     fillcolor=red!30,name=brick,action=draw*]
   \multido{\iA=0+1}{8}{%
     \psSolid[object=point,definition=solidgetsommet,args=brick \iA,
       linecolor=blue,name=P\iA]}
   \psSolid[object=line,linecolor=green,args=P0 P4,linewidth=5pt]
   \psSolid[object=line,linecolor=green,args=P4 P7,linewidth=5pt]
   \psSolid[object=line,linecolor=green,args=P7 P6,linewidth=5pt]
  \end{pspicture}


\end{document}
See the first example in http://tug.org/PSTricks/main.cgi?file=E ... /Gallery3D how to place text in the 3d space
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | Draw a Brick

Post by svend_tveskaeg »

Hi Herbert.

I have accomplished (most of) what I want:

Code: Select all

\documentclass{article}

\usepackage{auto-pst-pdf,pst-solides3d,pstricks-add}
\usepackage[locale=DE]{siunitx}
\definecolor{nicered}{rgb}{0.796,0.255,0.329}

\begin{document}

\begin{pspicture}[solidmemory](-4,-2)(4,1.5)
\psset{viewpoint=10 -30 15 rtp2xyz,Decran=30}
\psset{fontsize=20,linewidth=2pt}
  \psSolid[
    object=parallelepiped,
    a=2.28, b=1.08, c=0.54,
    RotZ=30,
    fillcolor=nicered,
    name=brick,
    action=draw*
  ]
  \multido{\iA=0+1,\iB=1+1}{8}{%
    \psSolid[
      object=point,
      definition=solidgetsommet,
      args=brick \iA,
      name=P\iA,
      action=none
    ]
  }
  \pspicture[showgrid,solidmemory](-4,-3)(4,2)
%    \pcline[offset=12pt](P6)(P7)
%    \ncput*[nrot=:U]{$l = \SI{22.8}{\cm}$}
    \rotatebox{-7}{\rput(-0.8,-1.65){$l = \SI{22.8}{\cm}$}}
    \rotatebox{34}{\rput(1.8,-3.1){$b = \SI{10.8}{\cm}$}}
    \rotatebox{-1}{\rput(4.6,0){$h = \SI{5.4}{\cm}$}}
  \endpspicture
\end{pspicture}

\end{document}
Issue: I would like the label text to be typed in math mode. (I had a look at the examples in section 11.12 of the pst-solides3d manual, but to the conclusion that it is not the way to go.)

Damned! I edited the wrong post.
Last edited by svend_tveskaeg on Tue Oct 30, 2012 9:31 pm, edited 5 times in total.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | Draw a Brick

Post by CrazyHorse »

svend_tveskaeg wrote: Issue: I would like the label text to be typed in math mode. (I had a look at the examples in section 11.12 of the pst-solides3d manual, but to the conclusion that it is not the way to go.)
the math mode is not possible here. All characters are passed to PostScript and then set. Use

Code: Select all

\pspicture[showgrid,solidmemory](...)(...)
and then put all math stuff with the default 2d macros like \uput or \rput. Later you can delete the showgrid option.
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | Draw a Brick

Post by svend_tveskaeg »

Okay. I have done the following:

Code: Select all

\documentclass{article}

\usepackage{auto-pst-pdf,pst-solides3d,pstricks-add}
\usepackage[locale=DE]{siunitx}
\definecolor{nicered}{rgb}{0.796,0.255,0.329}

\begin{document}

\begin{pspicture}[solidmemory](-4,-2)(4,1.5)
\psset{viewpoint=10 -30 15 rtp2xyz,Decran=30}
\psset{fontsize=20,linewidth=2pt}
  \psSolid[
    object=parallelepiped,
    a=2.28, b=1.08, c=0.54,
    RotZ=30,
    fillcolor=nicered,
    name=brick,
    action=draw*
  ]
  \multido{\iA=0+1,\iB=1+1}{8}{%
    \psSolid[
      object=point,
      definition=solidgetsommet,
      args=brick \iA,
      name=P\iA,
      action=none
    ]
  }
  \pspicture[showgrid,solidmemory](-4,-3)(4,2)
%    \pcline[offset=12pt](P6)(P7)
%    \ncput*[nrot=:U]{$l = \SI{22.8}{\cm}$}
    \rotatebox{-7}{\rput(-0.8,-1.65){$l = \SI{22.8}{\cm}$}}
    \rotatebox{34}{\rput(1.8,-3.1){$b = \SI{10.8}{\cm}$}}
    \rotatebox{-1}{\rput(4.6,0){$h = \SI{5.4}{\cm}$}}
  \endpspicture
\end{pspicture}

\end{document}
Can I somehow use the defined nodes P0,...,P7 within the

Code: Select all

\pspicture[showgrid,solidmemory](-4,-2)(4,2)
 ...
\endpspicture
environemt?
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | Draw a Brick

Post by CrazyHorse »

svend_tveskaeg wrote: Can I somehow use the defined nodes P0,...,P7 within the

Code: Select all

\pspicture[showgrid,solidmemory](-4,-2)(4,2)
 ...
\endpspicture
environemt?
no, the reason why I told you to use absoulte coordinates which can easily been find with the 2d coordinate system, drawn by showgrid
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: PSTricks | Draw a Brick

Post by svend_tveskaeg »

Okay. 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