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.

  • Why? That is, why do you want to do this? – cfr Nov 05 '15 at 02:54
  • I create an screw in tikz-3d once using a pic for one turn of the thread. – John Kormylo Nov 05 '15 at 04:54
  • I am not sure what you exactly mean. But have you checked tikz-3dplot? – Symbol 1 Nov 05 '15 at 06:29
  • Of course I checked tikz-3dplot. It is a great package, but could not find the way to use it for my problem. Please see the update on my question above. Thanks. – Herman Jaramillo Nov 05 '15 at 15:43
  • 2
  • 2
    For computation-heavy 3d stuff, you might want to check out Asymptote. 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 (recently updated). [I couldn't make the hyperlinks work, sorry.] – Charles Staats Nov 05 '15 at 16:21
  • I think this is a good alternative, if TikZ does not handle buffers of memory. – Herman Jaramillo Nov 05 '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 05 '15 at 16:26
  • Actually your comments gave me a new idea. Let us assume that my graph takes 30 seconds for processing. That is not a big deal as long as I process it only once. In "Asymptote" there is a way to re-compile the .tex file and process the graph only once with the command "latexmk" , whenever the graph has not changed. Is there such a thing for TiKz? I will post this as a new question. Thanks. – Herman Jaramillo Nov 05 '15 at 16:41
  • 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 06 '15 at 08: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 06 '15 at 08:36
  • @Symbol : I have not checked what you say but it sounds like music to my ears. You seem to be the expert on this subject and the only one that addressed my question correctly. Thank you very much! – Herman Jaramillo Nov 06 '15 at 15:28
  • @Symbol1 : The TiKz/pgf library would benefit in the drawing arc from the information in these link: http://math.stackexchange.com/questions/1507248/find-arc-between-two-tips-of-vectors-in-3d/1507943 that show two different mathematical algorithms to draw arcs in 3D from $A$ to $B$ with center at $O$. The implemtation in TiKz is disussed here: http://tex.stackexchange.com/questions/46850/how-can-i-draw-an-arc-from-point-a-b-on-a-3d-sphere-in-tikz/277299#277299 – Herman Jaramillo Nov 09 '15 at 14:15

1 Answers1

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