Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am searching for a solution to get nice looking circular polarized waves in my latex document. My goal is to get a graph that looks like this:

enter image description here

I do not want the graph to be animated but I can not even get it to plot a circular wave.

Any help would be highly appreciated.

share|improve this question
    
It might be worth informing that this blogger does projected animations, but with PSTricks. –  I am who I say I am Feb 22 '13 at 5:30
    
The program sketch does that kind of graphics, and produces tikz output. You can start from this answer which even contains a helix. –  JLDiaz Feb 22 '13 at 9:39
add comment

1 Answer

up vote 24 down vote accepted

Possibly something like this maybe? Not sure if it is quite right.

\documentclass{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[x={(0.75cm,.5cm)}, z={(1cm,-.25cm)}]

\tikzset{%
    xyz path/.style args={\x=#1; \y=#2; \z=#3; (#4)}{
        insert path={
            \foreach \step [evaluate={\x=#1; \y=#2; \z=#3;}] in {#4}{   
                -- (\x, \y, \z) } 
        }
    },
    cosine path/.style args={#1:#2}{
        xyz path={\x=cos(\step); \y=0; \z=\step/360; (#1, 5, ..., #2)},
        insert path={ coordinate (cosine path end) }
    },
    sine path/.style args={#1:#2}{
        xyz path={\x=0; \y=sin(\step); \z=\step/360; (#1, 5, ..., #2)},
        insert path={ coordinate (sine path end) }
    },
    spiral path/.style args={#1:#2}{
        xyz path={\x=cos(\step); \y=sin(\step); \z=\step/360; (#1, 5, ..., #2)},
        insert path={ coordinate (spiral path end) }
    },
    marker/.style={
        insert path={
            node [fill, circle,  inner sep=0pt, minimum size=#1] {}
        }
    }
}

\def\lastangle{135}
\def\cycles{5}

\foreach \cycle in {0,...,\cycles}{
    \tikzset{shift={(0, 0, \cycle)}}
    \ifnum\cycle=\cycles
        \let\endangle=\lastangle
    \else
        \def\endangle{360}
    \fi
    \draw [red] (1, 0, 0) [cosine path={0:\endangle}];
    \draw [green] (0, 0, 0) [sine path={0:\endangle}];
    \draw [blue, very thick] (1, 0, 0) [spiral path={0:\endangle}];
}

\tikzset{shift={(0,0,\cycles+\lastangle/360)}}

\draw [dotted, thick]
    (-2,-2, 0) -- (2,-2,0) -- (2,2,0) -- (-2,2,0) -- cycle
    (0,-2) -- (0,2) (-2,0) -- (2,0) 
    (1, 0) 
    \foreach \step [evaluate={\y=sin(\step); \x=cos(\step);}] in {0, 5, ..., 355}{  
            -- (\x, \y, 0) } ;

\draw [orange] (cosine path end) -- (spiral path end) -- (sine path end);
\draw [red] (0,0,0) -- (cosine path end) [marker=2pt];
\draw [green] (0,0,0) -- (sine path end) [marker=2pt];
\draw [blue, very thick] (0,0,0) -- (spiral path end) [marker=4pt];
\end{tikzpicture}

\end{document}          

enter image description here

EDIT Of course we can do better:

\documentclass{standalone}
\usepackage[active,tightpage]{preview}
\usepackage{tikz}
\PreviewEnvironment{tikzpicture}
\usetikzlibrary{backgrounds}
\begin{document}

\tikzset{%
    calculate step/.code=\pgfmathsetmacro\step{#1+5},
    cosine path/.style args={#1:#2}{
        insert path={ [calculate step=#1]
            (cos #1, 0, #1/360)  
            \foreach \t in {#1, \step, ..., #2}{ -- (cos \t, 0, \t/360) }
            coordinate (cosine path end) 
        }
    },
    sine path/.style args={#1:#2}{
        insert path={ [calculate step=#1]
            (0, sin #1, #1/360)  
            \foreach \t in {#1, \step, ..., #2}{ -- (0, sin \t, \t/360) }  
            coordinate (sine path end) 
        }
    },
    spiral path/.style args={#1:#2}{
        insert path={ [calculate step=#1]
            (cos #1, sin #1, #1/360)  
            \foreach \t in {#1,\step, ..., #2}{ -- (cos \t, sin \t, \t/360) }  
            coordinate (spiral path end) 
        },
    },
    marker/.style={
        insert path={
            node [fill, circle,  inner sep=0pt, minimum size=#1] {}
        }
    },
    background/.style={
        background rectangle/.style={fill=black}, 
        show background rectangle
    },
    cosine/.style={
        red
    },
    sine/.style={
        green
    },
    spiral/.style={
        cyan,
        very thick
    },
    indicator/.style={
        orange
    },
    grid/.style={
        white,
        loosely dotted,
        thick
    },
    axis/.style={
        white,
        thick
    }
}

\def\cycles{4}

\foreach \phase in {0, 10, ..., 350}{%
\begin{tikzpicture}[x={(0.75cm, .5cm)}, z={(1cm, -.25cm)}, 
    background, 
    line cap=round
]
\draw [axis] (0, 0, \phase/360) -- (0, 0, \cycles+\phase/360);
\foreach \cycle in {0,...,\cycles}{
    \tikzset{shift={(0, 0, \cycle)}}
    \ifnum\cycle=0
        \let\startangle=\phase
    \else
        \def\startangle{0}
    \fi
    \ifnum\cycle=\cycles
        \let\endangle=\phase
    \else
        \def\endangle{360}
    \fi
    \draw [cosine] [cosine path={\startangle:\endangle}];
    \draw [sine]   [sine path={\startangle:\endangle}];
    \draw [spiral] [spiral path={\startangle:\endangle}];
}

\begin{scope}[shift={(0, 0, \cycles+\phase/360)}]

\draw [grid]
    (-2, -2, 0) -- (2, -2, 0) -- (2, 2, 0) -- (-2, 2, 0) -- cycle
    (0, -2) -- (0, 2) (-2, 0) -- (2, 0) 
    (1, 0) \foreach \t in {0, 5, ..., 355}{ -- (cos \t, sin \t, 0) };

\draw [indicator] (cosine path end) -- (spiral path end) -- (sine path end);
\draw [cosine]    (0, 0, 0) -- (cosine path end) [marker=2pt];
\draw [sine]      (0, 0, 0) -- (sine path end)   [marker=2pt];
\draw [spiral]    (0, 0, 0) -- (spiral path end) [marker=4pt];

\end{scope}

\useasboundingbox 
    [shift={(0, 0, \phase/360)}]
    (-1.125, -1.125, 0) -- (1.125, -1.125, 0) -- 
    (1.125, 1.125, 0) -- (-1.125, 1.125, 0) -- cycle
    [shift={(0, 0, \cycles)}]
    (-2.125, -2.125, 0) -- (2.125, -2.125,0) -- 
    (2.125, 2.125, 0) -- (-2.125, 2.125, 0) -- cycle;
\end{tikzpicture}}
\end{document}

enter image description here

Note that in the PDF produced by the above code, the spiral goes backwards so that when Gimp produces the animation it goes in the other direction.

share|improve this answer
    
Thank you very much! I guess I am going t use this solution –  Daniel M Feb 22 '13 at 22:23
    
Very nice! Just for information. With last standalone package, option tikz places every tikzpicture in a different page, and you can avoid loading preview package. –  Ignasi Feb 24 '13 at 10:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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