5

Let me be specific by posting an example:

The following small code draw a piece of helix (an ugly one)

 \documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{tikz}

    \begin{document}

    \begin{tikzpicture}
                % axes
      \coordinate (O) at (0,0,0);
      \coordinate (X) at (3,0,0);
      \coordinate (Y) at (0,3,0);
      \coordinate (Z) at (0,0,3);

      \def\scl{3.29} % steps
      \foreach \t in {0,1,...,360}
      {
        \draw[line width=1pt,color=red, opacity=0.4, dashed] 
        ({cos(\t)},   {sin(\t)}, {\scl*\t/360})--({cos(\t+7)},{sin(\t +7)},
        {\scl*(\t+7)/360});
      }

                % draw axes
      \draw[-latex] (O) -- (X) node[anchor=west] {$X$};
      \draw[-latex] (O) -- (Y) node[anchor=west] {$Y$};
      \draw[-latex] (O) -- (Z) node[anchor=west] {$Z$};

    \end{tikzpicture}



    \end{document}

Is there a way to save the points in memory and call some "pgfplots" instruction to plot them?

Let me clarify that I do not want to plot a helix. I want to plot anything that even does not have an equation but it is a set of points that I create within TiKz.

Thanks.


I see that I have not been clear about this, so let me add some extra information. Please look at the following link arc between points A and B in a 3D sphere

The last plot (as at this moment) is a sphere with 5 arcs. I computed those arcs in TiKz and the code to compute them is in the post. Since each point is drawn with "node[]" it takes more than 30 seconds in my computer to process. Plots like this usually take me 1 or 2 seconds. The reason is that the code is too high level and very slow. Besides, I do not have much leverage. I can define color and point density, that is all, I would like to call a TiKz function where I can define many attributes. Thanks.

In summary two facts that I want to know are:

  1. Is there "arrays", or "pointers" like in C++ (or C) code? where I can store a set of points?
  2. Is there a function in TiKz that reads from memory a set of points and plot them in 3D?

Thanks.

13
  • 2
  • 2
    For computation-heavy 3d stuff, you might want to check out [Asymptote](asymptote.sourceforge.net). This goes double since you seem comfortable with C-style syntax. (Asymptote uses C-style syntax and has arrays, among other conveniences absent from TeX.) See also [my tutorial](math.uchicago.edu/~cstaats/Charles_Staats_III/Notes_and_papers_files/asymptote_tutorial.pdf) (recently updated). [I couldn't make the hyperlinks work, sorry.] – Charles Staats Nov 5 '15 at 16:21
  • 2
    Asymptote is a fine tool. I like it. The thing is that for high quality graphic, you need to set the "render=16" or higher, and for 3D plots with surfaces and curves, this also takes a good 30 seconds of process. Of course there is a great tool called "latexmk" which ignores the asymptote changes so you only need to compile it when you do changes on that particular plot. In addition, this creates additional auxiliary files (with extension .asy), and if we use "latexmk" this in addition creates additional files. TiKz is, for me, the best cost/benefit solution. But thanks for the tip. – Herman Jaramillo Nov 5 '15 at 16:26
  • 2
    Drawing arcs is a nightmare for TikZ in the sense that arcs are not Bezier curves. Nor are the projection of 3D-arcs. So preferring vector graphics rather then high-quality bitmap makes little sense in this case. TikZ does has a external library which compiles the pictures once and for all. But again, it is implemented by creating auxiliary files just like Asymptote. So it is all up to you. @William 'Ike' Eisenhauer's comment might help in case you still choose TikZ. – Symbol 1 Nov 6 '15 at 8:24
  • 2
    To answer your updated questions directly: (1) No, TeX has no array in the beginning. But one can implement array by naming a control sequence as \ArrayApple101. This could be done by \csname ArrayApple\the\counterApple\endcsname. (2) Do you mean \addplot3? see 4.6.2 The \addplot3 Command: Three Dimensional Coordinate Input of PGFPLOTS manual. – Symbol 1 Nov 6 '15 at 8:36
2

I found a solution to my question. This solution was inspired in another StackExchange post

Helix on a cylinder

The main idea is the use of the function "\pgfplotfunction"

Here is a piece of code:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{pgfplots}
\usetikzlibrary{shapes}
\tdplotsetmaincoords{60}{110}


\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}[tdplot_main_coords]
  \node [cylinder,rotate=90,draw,aspect=2,minimum width=2cm,minimum height=3.5cm](C){};


  \begin{scope}[color=black, dashed]
  \pgfplothandlerlineto
  \pgfplotfunction{\t}{-90,-89,...,15}
       {\pgfpointxyz {cos(\t)}{sin(\t)}{-0.25+\t/360}} 
       \pgfusepath{stroke}
  \end{scope}

  \begin{scope}[color=red]
  \pgfplothandlerlineto
  \pgfplotfunction{\t}{15,16,...,110}
       {\pgfpointxyz {cos(\t)}{sin(\t)}{-0.25+\t/360}} 
       \pgfusepath{stroke}
  \end{scope}

  \begin{scope}[color=red, dashed]
  \pgfplothandlerlineto
  \pgfplotfunction{\t}{110,111,...,303}
       {\pgfpointxyz {cos(\t)}{sin(\t)}{-0.25+\t/360}} 
       \pgfusepath{stroke}
  \end{scope}


  \begin{scope}[color=red]
  \pgfplothandlerlineto
  \pgfplotfunction{\t}{303,304,...,340}
       {\pgfpointxyz {cos(\t)}{sin(\t)}{-0.25+\t/360}} 
       \pgfusepath{stroke}
  \end{scope}



  \begin{scope}[color=black, dashed]
  \pgfplothandlerlineto
  \pgfplotfunction{\t}{340,341,...,370}
       {\pgfpointxyz {cos(\t)}{sin(\t)}{-0.25+\t/360}} 
       \pgfusepath{stroke}
  \end{scope}

  \def\ang{340}
  \pgfmathsetmacro\bx{cos(\ang)}
  \pgfmathsetmacro\by{sin(\ang)}
  \pgfmathsetmacro\bz{-0.24+ \ang/360}

  \coordinate (B) at (\bx,\by,\bz);



  \draw[fill] (0.9922,0.25,-0.2) circle [x=1cm,y=1cm,radius=0.045]node[below]{$A$};
  \draw[fill] (B) circle [x=1cm,y=1cm,radius=0.045]node[below]{$B$};
\end{tikzpicture}
\end{document}

and here is the graph resulting from it.

helix on a cylinder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.