I have been trying to get my head around drawing on latex and have not been able to get anywhere. I was just wondering if anyone could help me with the following shape? Just need a bit of guidance still quite new to the program.
1 Answers
The following solution uses the experimental(?) package tikz3d.sty from the TeX.SX launchpad. To install it, do the following:
- Download
tikz3d.dtxfrom http://bazaar.launchpad.net/~tex-sx/tex-sx/development/view/head:/tikz3d.dtx. Run pdflatex on the
dtxfile to extracttikz3d.sty.pdflatex tikz3d.dtxRun
pdflatexonce more ontikz3d.dtxto obtaintikz3d.pdf, the documentation of the package.
Now pdflatexing the following code should result in the picture above.
\documentclass{minimal}
\usepackage{tikz}
\usepackage{tikz3d}
\begin{document}
\begin{center}
\begin{tikzpicture}[3d/perspective eye={0,5,-10},>=stealth]
\newcommand\xa{5} % half of width at bottom
\newcommand\xb{2} % half of width at top
\newcommand\ya{2} % height
\newcommand\za{2} % half of depth
\coordinate (A) at (3d cs:-\xa,0,-\za);
\coordinate (B) at (3d cs: \xa,0,-\za);
\coordinate (C) at (3d cs: \xa,0, \za);
\coordinate (D) at (3d cs:-\xa,0, \za);
\coordinate (E) at (3d cs:-\xb,\ya, 0);
\coordinate (F) at (3d cs: \xb,\ya, 0);
\draw[thick] (D) -- node[left]{$w$} (A) -- node[below]{$l$} (B) -- (C);
\draw[dashed] (C) -- (D);
\draw[thick] (A) -- (E) -- (D);
\draw[thick] (B) -- (F) -- (C);
\draw[thick] (E) -- node[above]{$t$} (F);
\draw[<->,dashed] (3d cs:1,0,0) -- node[right]{$h$} (3d cs:1,\ya,0);
\end{tikzpicture}
\vspace{1cm}
\begin{tikzpicture}[3d/perspective eye={0,5,-10}]
\newcommand\xa{6} % half of width at bottom, shifted
\newcommand\xb{2} % half of width at top
\newcommand\xc{3} % half of width at top, shifted
\newcommand\ya{2} % height
\newcommand\za{2} % half of depth
\coordinate (A) at (3d cs:-\xa,0,-\za);
\coordinate (B) at (3d cs: \xa,0,-\za);
\coordinate (C) at (3d cs: \xa,0, \za);
\coordinate (D) at (3d cs:-\xa,0, \za);
\coordinate (E) at (3d cs:-\xb,\ya, 0);
\coordinate (F) at (3d cs: \xb,\ya, 0);
\coordinate (E') at (3d cs:-\xc,\ya, 0);
\coordinate (F') at (3d cs: \xc,\ya, 0);
\coordinate (a) at (3d cs:-\xb,0,-\za);
\coordinate (b) at (3d cs: \xb,0,-\za);
\coordinate (c) at (3d cs: \xb,0, \za);
\coordinate (d) at (3d cs:-\xb,0, \za);
\coordinate (a') at (3d cs:-\xc,0,-\za);
\coordinate (b') at (3d cs: \xc,0,-\za);
\coordinate (c') at (3d cs: \xc,0, \za);
\coordinate (d') at (3d cs:-\xc,0, \za);
\draw[thick] (a') -- (A) -- (D) -- (E') -- (A);
\draw[dashed] (d') -- (D);
\draw[thick,fill=gray] (a') -- (E') -- (d') -- cycle;
\draw[thick] (b') -- (B) -- (C) -- (F') -- (B);
\draw[dashed] (c') -- (C);
\draw[thick,fill=gray] (b') -- (F') -- (c') -- cycle;
\draw[thick] (a) -- (b) -- (F) -- (E) -- (a);
\draw[dashed] (a) -- (d) -- (c) -- (b);
\draw[dashed] (d) -- (E);
\draw[dashed] (c) -- (F);
\end{tikzpicture}
\end{center}
\end{document}
The code can be simplified by setting the coordinate system globally to 3d cs. If you include the lines
\makeatletter
\def\tikz@parse@splitxyz#1#2#3,#4,{%
\def\@next{\tikz@scan@one@point#1(3d cs:{#2},{#3},{#4})}%
}
\makeatother
in the preamble, then you can remove the prefix 3d cs: in all of the coordinates, writing e.g. just (-\xa,0,-\za) instead of (3d cs:-\xa,0,-\za).
- 49,614
-
Thank you so much for taking this time to explain it to me. I have run the package and have obtained the pdf file but when I try and run the code it is giving me the following message: "("C:\Program Files\MiKTeX 2.9\tex\generic\pgf\frontendlayer\tikz\libraries\tikz librarytopaths.code.tex")))
! LaTeX Error: File `tikz3d.sty' not found.
Type X to quit or
to proceed, or enter new name. (Default extension: sty) Enter file name: " I am not sure what to do. Apologies, still trying to wrap my head around LateX.
– aml1005 Feb 08 '17 at 16:43 -
@aml1005 Check that
tikz3d.styand the file with the code above are in the same directory; then it should work. If not, it is a specialty of MiKTeX, which I do not use. In the latter case ask on this site why MikTeX doesn't find the file. – gernot Feb 08 '17 at 16:46 -
this is going to sound very stupid and i'm sorry if it does but how would i make sure that it is? And will do, thanks again for everything I really appreciate it! – aml1005 Feb 08 '17 at 17:10
-
@aml1005 Open the directory that contains the code from above using the explorer. Then you should also see
tikz3d.sty. If not, my guess is that after downloadingtikz3d.dtxended up in someDownloadsfolder; running latex on it will store the generatedtikz3d.styalso in theDownloadsfolder instead of in your TeX working directory. So you will have to movetikz3d.stymanually (with the explorer) fromDownloadsto the TeX working directory. – gernot Feb 08 '17 at 17:18


pstrickspackages:pst-ob3d,pst-3dplot,pst-solides3d,pst-perspective. – Bernard Feb 08 '17 at 14:04