0

I want to plot a sequence of cones using tikz. My cones have arbitary coordinates that I calculated beforehand. For n cones, I have the coordinates of n+1 circles, each as a tuple of (depth, center, radius). The circles all lay in the X-Y plane.

I have something like this in mind:

enter image description here

I like the cross sections, as they provide an impression of depth. This is an illustration for an undergrad thesis, if you have suggestions feel free to comment. A cross section (in the X-Z plane) will be next to ist, with proper axes and units. This is just there to provide a proper 3D impression.


To explain a bit more: I don't want the code (after all, I did not give any coordinates..) but I saw this in the manual:

The second way of specifying points is to put them in an external file. Currently, the only format that TikZ allows is the following: Each line of the file should contain one line starting with two numbers, separated by a space. Anything following the two numbers on the line is ignored.

Now I would like to read arbitrary data from file. Something like (depth, center_x, center_y, radius) or so, whatever is easiest to read by tikz. I have not done this before and would be particularly interested in getting the values from a file into the foreach loop if tikz. I think I can handle the actual plotting from there.

4

1 Answer 1

2

With the use of the datatool package this code is what I ended up with:

\tikzsetnextfilename{MyCool3dGraphic}
\begin{tikzpicture}
    \DTLloaddb[keys={za,xa,ra,zb,xb,rb}]{coordinates}{Bilder/kh_3d.dat}
    \pgfplotsset{
        colormap={blackwhite}{gray(0cm)=(1); gray(1cm)=(0.8)}
    }
    \begin{axis}[
        height=15cm, width=15cm,
        domain=0:5,
        y domain=0:2*pi,
        samples=2,
        samples y=32,
        grid=both,
        xmin=-50e-6,
        xmax=50e-6,
        scaled ticks=false,
        xlabel=x,
        xtick={-40e-6,-20e-6,0,20e-6,40e-6},
        xticklabels={-40,-20,0,\si{\micro\metre},40},
        ylabel=y,
        ytick={-40e-6,-20e-6,0,20e-6,40e-6},
        yticklabels={-40,-20,{~0},\si{\micro\metre},40},
        zlabel=z,
        ztick={-5e-4,-4e-4,-3e-4,-2e-4,-1e-4,0},
        zticklabels={{-0,5},{-0,4},{-0,3},{-0,2},mm,0},
        ymin=-50e-6,
        ymax=50e-6,
        zmax=0,
        zmin=-508e-6,
        unit vector ratio=3 3 1]

        \def\za{5}
        \def\xa{1}
        \def\ra{1.5}

        \def\zb{0}
        \def\xb{0}
        \def\rb{1}
        \def\rsc{(\rb-\ra)/(\zb-\za)}
        \def\xsc{(\xb-\xa)/(\zb-\za)}

        \DTLforeach*{coordinates}{\za=za, \xa=xa, \ra=ra, \zb=zb, \xb=xb, \rb=rb}{
            \addplot3[surf, shader=flat, draw=black, z buffer=sort, domain=\za:\zb]
            ({(\ra + (x-\za) * \rsc) * cos(deg(y)) + \xa + (x-\za) * \xsc},
            { (\ra + (x-\za) * \rsc) * sin(deg(y))},
            {x});
        }
    \end{axis}

\end{tikzpicture}

This uses a custom made file with the proper data for each cone. That is bottom z-value, center and radius as well as upper z-value center and radius. (6 columns) It is important to use only 2 samples for the domain, as pdftex will take an eternity otherwise. (or run out of memory eventually)

So the picture looks like this: pgf plot

That picture apparently goes to the limits of tex and beyond. While I could compile a minimum example with pdftex, I could not integrate it into my thesis. pdftex runs out of memory. (that is, with --extra-mem-bot=200000000) Yes, this also happend when I used externalization. The solution was then to tell tikz to call luatex for generating the pictures:

\tikzset{external/system call={lualatex \tikzexternalcheckshellescape --interaction=nonstopmode --jobname "\image" "\texsource"}}

which works until now.

You must log in to answer this question.

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