17

I would like to draw a transparent, `flattened cube' in perspective with dotted lines from both vanishing points to each of the vertices of the 3D solid. Is there a PSTricks package for this?

It is much like Jan Hlavacek's answer to What is the easiest way to draw 3D cube with TikZ? but with the vanishing points and dotted lines from these, and then the `cube' should be transparent. Unfortunately I do not know TikZ.

Update

The following code shows what I would like to achieve:

screenshot

\documentclass{article}

\usepackage{auto-pst-pdf,pstricks-add}

\begin{document}

\begin{figure}
\def\HAa{-5.25 }
\def\HBa{12.5 }
\def\Ab{-0.85 }
\def\Bb{3.05 }
\def\Ia{-1.8 }
\def\Ja{2.65 }
 \centering
 \psset{unit=0.765cm}
  \begin{pspicture}(\HAa,\Ab)(\HBa,\Bb)
   \pnode(!\HAa 0){H1}
   \psdot(H1)
   \pnode(!\HBa 0){H2}
   \psdot(H2)
   \pnode(!\Ia 0){P9}
   \pnode(!\Ja 0){P10}
   \pcline[linestyle=dashed](H1)(P9)
   \pcline[linestyle=dashed](P10)(H2)
   \pnode(!0 \Ab){P1}
   \pnode(!0 \Bb){P2}
   \pnode(!\Ia \HAa \Ia sub \HAa div \Ab mul){P3}
   \pnode(!\Ia \HAa \Ia sub \HAa div \Bb mul){P4}
   \pnode(!\Ja \HBa \Ja sub \HBa div \Ab mul){P5}
   \pnode(!\Ja \HBa \Ja sub \HBa div \Bb mul){P6}
   \psIntersectionPoint(H1)(P5)(H2)(P3){P7}
   \psIntersectionPoint(H1)(P6)(H2)(P4){P8}
   \multido{\i=1+1}{8}{\psdot(P\i)}
   \pcline(P1)(P2)
   \pcline(P1)(P3)
   \pcline(P2)(P4)
   \pcline(P3)(P4)
   \pcline(P1)(P5)
   \pcline(P2)(P6)
   \pcline(P5)(P6)
  \psset{linestyle=dotted}
   \pcline(P3)(H1)
   \pcline(P4)(H1)
   \pcline(P5)(H1)
   \pcline(P6)(H1)
   \pcline(P3)(H2)
   \pcline(P4)(H2)
   \pcline(P5)(H2)
   \pcline(P6)(H2)
   \pcline(P7)(P8)
  \end{pspicture}
\end{figure}

\end{document}

I would like to make this drawing when knowing just the width, depth, and height of the box plus the point of view, instead of maunally calculating the \def values.

P.S. I do not know how to include images, sorry.

Update 2

I have changed the code a bit. (The \def names are changed and the hiddens lines in the cubiod are dashed instead of dotted.)

\documentclass{article}

\usepackage{pstricks-add}

\begin{document}

\begin{figure}
\def\venstre{-5.25 }
\def\hoejre{12.5 }
\def\vinkel{-0.85 }
\def\hoejde{3.05 }
\def\dybde{-1.8 }
\def\bredde{2.65 }
 \centering
 \psset{unit=0.684cm}
  \begin{pspicture}(\venstre,\vinkel)(\hoejre,\hoejde)
   \pnode(!\venstre 0){H1}
   \pnode(!\hoejre 0){H2}
   \psdot(H1)
   \psdot(H2)
   \pnode(!\dybde 0){P9}
   \pnode(!\bredde 0){P10}
   \pcline[linestyle=dashed](H1)(P9)
   \pcline[linestyle=dashed](P10)(H2)
   \pnode(!0 \vinkel){P1}
   \pnode(!0 \hoejde){P2}
   \pnode(!\dybde \venstre \dybde sub \venstre div \vinkel mul){P3}
   \pnode(!\dybde \venstre \dybde sub \venstre div \hoejde mul){P4}
   \pnode(!\bredde \hoejre \bredde sub \hoejre div \vinkel mul){P5}
   \pnode(!\bredde \hoejre \bredde sub \hoejre div \hoejde mul){P6}
   \psIntersectionPoint(H1)(P5)(H2)(P3){P7}
   \psIntersectionPoint(H1)(P6)(H2)(P4){P8}
   \multido{\i=1+1}{8}{\psdot(P\i)}
   \pcline(P1)(P2)
   \pcline(P1)(P3)
   \pcline(P2)(P4)
   \pcline(P3)(P4)
   \pcline(P1)(P5)
   \pcline(P2)(P6)
   \pcline(P5)(P6)
  \psset{linestyle=dotted}
   \pcline(P3)(H1)
   \pcline(P4)(H1)
   \pcline(P7)(H1)
   \pcline(P8)(H1)
   \pcline(P7)(H2)
   \pcline(P8)(H2)
   \pcline(P5)(H2)
   \pcline(P6)(H2)
  \psset{linestyle=dashed}
   \pcline(P7)(P3)
   \pcline(P7)(P5)
   \pcline(P7)(P8)
   \pcline(P8)(P4)
   \pcline(P8)(P6)
  \end{pspicture}
\end{figure}

\end{document}

enter image description here

Update 3

Here is what I ended up with:

\documentclass{article}

\usepackage{pst-solides3d}

\begin{document}

\begin{figure}
 \psset{viewpoint=10 45 8 rtp2xyz,Decran=5}
  \begin{pspicture}[solidmemory](-5,-5)(6,12)
   \psSolid[object=point,args=6 0 1.42,name=L]
   \psSolid[object=point,args=-12 9.75 1.42,name=R]
   \psSolid[object=line,linecolor=red!40,linestyle=dashed,linewidth=2pt,args=R L]
   \psSolid[object=parallelepiped,a=4.56,b=4.56,c=3.90,RotZ=-8,fillcolor=yellow!40,name=Cube,action=draw*](0 0 2)
   \multido{\iA=0+1}{8}{%
     \psSolid[object=point,definition=solidgetsommet,args=Cube \iA,name=C\iA]
   }
   \multido{\iA=0+1}{8}{%
     \psSolid[object=line,linecolor=blue!40,linestyle=dotted,args=L C\iA]
     \psSolid[object=line,linecolor=blue!40,linestyle=dotted,args=R C\iA]
   }
   \psSolid[object=parallelepiped,a=4.56,b=4.56,c=3.90,RotZ=-8,name=Cube,action=draw](0 0 2)
  \end{pspicture}
\end{figure}

\end{document}
  • 3
    At present, this is very much a "do-it-for-me" question. Please edit your post to give some indication of what you've tried so far. – Andrew Uzzell Oct 18 '12 at 10:21
  • It was not meant as that; sorry. I really just want to know if there is a PSTricks package for doing this. (Way too many details regarding the drawing itself, I see that now.) – Svend Tveskæg Oct 18 '12 at 10:31
  • I think pst-solides3d could be of interest for you. You could have a look at some of Herbert's answers, he usually provides excellent answers at a fraction of the hassle of a TikZ answer. – Tom Bombadil Oct 18 '12 at 11:40
  • @Tom Bombadil: Arrrh, interesting! I only had a look at the pst-3d package. – Svend Tveskæg Oct 18 '12 at 11:44
  • I cannot find anything (for me) useful in the answers from @Herbert so I will contact him and ask if there is a package or if he has a solution. – Svend Tveskæg Oct 18 '12 at 13:22
  • Have a look at this question. There Herbert uses \psSolid[object=dodecahedron, and looking at the manual, section 3.1 (The predefined solids and their parameters), you can find, for instance, cube. – Tom Bombadil Oct 18 '12 at 16:08
  • It is not exactly what I am looking for. It is actually a `flattened cube' (not a cube as in the manual) in a 2 vanishing points perspective, just as the example Jason Whyte has refered to. – Svend Tveskæg Oct 18 '12 at 16:50
  • I have come across the awesome package pst-anamorphosis (documentation at melusine.eu.org/syracuse/G/pst-anamorphosis/doc) but I do not speak French. If someone could help me create the desired result using this package, I would much appreciate it. (Maybe now someone other than @Herbert can help. :-) – Svend Tveskæg Oct 28 '12 at 10:48

4 Answers4

9

Unfortunately, I don't know pstricks, but here's A TikZ solution:

Code

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{calc,intersections}

\begin{document}

\begin{tikzpicture}
\coordinate (V1) at (-7,1);
\coordinate (V2) at (5,1);

\fill (V1) circle (0.05) node[left] {V1};
\fill (V2) circle (0.05) node[right] {V2};

\pgfmathsetmacro{\cubelength}{3}

\coordinate (A) at (0,0);
\coordinate (B) at ($(A)!\cubelength cm!(V2)$);
\coordinate (D) at ($(A)!\cubelength cm!(V1)$);

\path[name path=BV1] (B) -- (V1);
\path[name path=DV2] (D) -- (V2);

\path[name intersections={of=BV1 and DV2}] (intersection-1);
\coordinate (C) at (intersection-1);

\coordinate (E) at (0,3);

\path[name path=Bup] (B) -- ++(0,\cubelength);
\path[name path=Dup] (D) -- ++(0,\cubelength);
\path[name path=EV1] (E) -- (V1);
\path[name path=EV2] (E) -- (V2);

\path[name intersections={of=Bup and EV2}] (intersection-1);
\coordinate (F) at (intersection-1);

\path[name intersections={of=Dup and EV1}] (intersection-1);
\coordinate (H) at (intersection-1);

\path[name path=FV1] (F) -- (V1);
\path[name path=HV2] (H) -- (V2);

\path[name intersections={of=FV1 and HV2}] (intersection-1);
\coordinate (G) at (intersection-1);

\foreach \x in {A,B,C,D,E,F,G,H} \fill (\x) circle (0.05) node[below right,circle] {\x};

\foreach \s\e in {A/B,D/A,A/E,B/F,D/H,E/F,F/G,G/H,H/E} \draw (\s) -- (\e);

\foreach \s\e in {B/C,C/D,C/G} \draw[densely dashed] (\s) -- (\e);

\foreach \p in {C,D,G,H} \draw[dotted] (\p) -- (V1);

\foreach \p in {B,C,F,G} \draw[dotted] (\p) -- (V2);

\path[name path=V1V2] (V1) -- (V2);

\draw[name intersections={of={Bup and V1V2},name=R}] (V2) -- (R-1);

\draw[name intersections={of={Dup and V1V2},name=L}] (V1) -- (L-1);

\draw[dotted] (L-1) -- (R-1);

\end{tikzpicture}

\end{document}

Output

enter image description here

Tom Bombadil
  • 40,123
  • This is exactly what I want (but with PSTricks)! I will, however, accept your answer if Herbert or someone else do not give a PSTricks solution. – Svend Tveskæg Oct 28 '12 at 12:17
9
\documentclass{article}
\usepackage{pst-solides3d}    
\begin{document}

\psset{viewpoint=10 60 15 rtp2xyz,Decran=5}
\begin{pspicture}[solidmemory](-5,-5)(6,12)
\psSolid[object=point,args=10 -36 0,name=L]
\psSolid[object=point,args=-36 10 0,name=R]
\psSolid[object=line,linecolor=blue,linestyle=dashed,linewidth=2pt,args=R L]
\psSolid[object=parallelepiped,a=6,b=3,c=3,RotZ=30,name=Cube,action=draw*](0 0 2)
\multido{\iA=0+1}{8}{%
  \psSolid[object=point,definition=solidgetsommet,args=Cube \iA,name=C\iA]}
\multido{\iA=0+1}{8}{%
  \psSolid[object=line,linecolor=blue!40,linestyle=dotted,args=L C\iA]
  \psSolid[object=line,linecolor=blue!40,linestyle=dotted,args=R C\iA]}
\psSolid[object=parallelepiped,a=6,b=3,c=3,RotZ=30,name=Cube,action=draw](0 0 2)
\end{pspicture}

\end{document}

enter image description here

  • Wow! This answer is hereby accepted.

    Thank you to both Tom Bombadil and Herbert.

    – Svend Tveskæg Oct 28 '12 at 12:19
  • I was a too impressed by the code to have a proper look at it. I would like the cube to be a flattened cube, i.e., a box. The height shold be something like 90 % of both the width and depth. Is this possible? – Svend Tveskæg Oct 28 '12 at 12:44
  • What is a "flattened cube"? –  Oct 28 '12 at 12:48
  • 1
    Then it is not a cube. Use object=parallelepiped,a=..,b=..,c=.. –  Oct 28 '12 at 12:53
  • Is it possible to draw the black lines (both the solid and the dotted) after the blue lines? I would like the black ones to be on top, if the lines intersect. Therefore, I tried to change the order of the lines in the code, but that is not possible (do to dependencies, I guess). – Svend Tveskæg Oct 28 '12 at 15:38
  • 1
    draw the box twice, at the first time with action=none and the second time with action=draw. This one before \end{pspicture} –  Oct 28 '12 at 15:48
  • Perfect. One last thing: How do I draw a dashed line between the two vanishing points? I tried \pcline(L)(R) but that messes everything up. – Svend Tveskæg Oct 28 '12 at 16:02
  • 1
    draw it also as a solid object with linestyle=dashed, args=L R –  Oct 28 '12 at 16:11
  • Hmm... I assumed that the parallelepiped would hide the dashed line (= the horizon) at the segment where the first is in front of the latter. How is this done? (After this, the drawing looks like the one I drew, i.e., I will stop now.) – Svend Tveskæg Oct 28 '12 at 16:18
  • 1
    if it should be a hiddenline, then you have to use action=none,name=... for all objects which should be drawn together with taken hidden lines and surfaces into account. AT the very end you use \psSolid[object=fusion,base=...] where base gets all defined names. You can find simple examples on http://PSTricks.tug.org –  Oct 28 '12 at 16:41
8

Tikz is a very powerful package with many examples available. Have a look at this example:

enter image description here

Is this something like what you are after?

Tom Bombadil
  • 40,123
Jason Whyte
  • 1,408
8

Here's something to get you started using the pst-solides3d package as requested.

enter image description here

I've borrowed experience from Werner's excellent answer to pst-solides3d and hidden lines

Your first step in constructing the solid is to specify its verticies:

  sommets= 
    0 0 0 
    3 0 0 
    3 3 0 
    0 3 0 
    0 3 1 
    0 0 1 
    3 0 1 
    3 3 1,

You can check if you got it right by using

  action=draw,num=all,show=all,

which gives

enter image description here

Finally you construct the solid by forming the faces- join the vertices together in an anti-clockwise direction

  faces={
    [2 1 0 3] % bottom face
    [6 5 0 1] % left face
    [7 6 1 2] % front face
    [4 7 2 3] % right face
    [3 0 5 4] % back face
    [7 4 5 6] % top face
    }]% 

The complete MWE is below. See page 34-35 of pst-solides3d for a very similar example.

\documentclass{article}
\usepackage{pst-solides3d}% http://ctan.org/pkg/pst-solides3d

\begin{document}

\begin{pspicture}(-2,-1)(3,4) 
\psset{viewpoint=25 8 5,Decran=100}
\psSolid[object=new, 
  fillcolor=green!60,
  opacity=0.3,
  action=draw*,%num=all,show=all,
  sommets= 
    0 0 0 
    3 0 0 
    3 3 0 
    0 3 0 
    0 3 1 
    0 0 1 
    3 0 1 
    3 3 1,
  faces={
    [2 1 0 3] % bottom face
    [6 5 0 1] % left face
    [7 6 1 2] % front face
    [4 7 2 3] % right face
    [3 0 5 4] % back face
    [7 4 5 6] % top face
    }]% 
\end{pspicture}
\end{document}

And if you want to colour the sides, you can use fcol

screenshot

\documentclass{article}
\usepackage{pst-solides3d}% http://ctan.org/pkg/pst-solides3d

\begin{document}

\begin{pspicture}(-2,-1)(3,4) 
\psset{viewpoint=25 8 5,Decran=100,solidmemory}
\psSolid[object=new, 
  fillcolor=green!60,
  name=Mycube,
  opacity=0.3,
  action=none,%num=all,show=all,
  sommets= 
    0 0 0 
    3 0 0 
    3 3 0 
    0 3 0 
    0 3 1 
    0 0 1 
    3 0 1 
    3 3 1,
  faces={
    [2 1 0 3] % bottom face
    [6 5 0 1] % left face
    [7 6 1 2] % front face
    [4 7 2 3] % right face
    [3 0 5 4] % back face
    [7 4 5 6] % top face
    }]% 
    \psSolid[fcol=2 (Apricot)
                  3 (ForestGreen)
                  5 (WildStrawberry),
    object=load,load=Mycube,action=draw*]
\end{pspicture}
\end{document}
cmhughes
  • 100,947