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.

It would be nice to have a decoration style that reproduces the sign of an optic fiber. In this way, when drawing optic schemes it would be really easy to indicate that a fiber (drawn as a line with such Fiber-Optic-Style decoration) is connecting two optic devices (represented by nodes).

The sign to represent a fiber optic is represented in the following picture.

enter image description here

Actually, the centers of the circles should be more spaced apart, but this is the simple picture I have found. Is there a way to modify the decoration style coil to do this?

It would be even more nice to be able to set the space between the circles and their diameter.

EDIT

Using phase of tikz's snake decoration I manage to define a decoration that draw the fiber.

However, there's three catches.

First, I'd like to set a key to define the space between the centers of the circles, rather that shift by .25\pgfdecorationsegmentamplitude, such that one can choose that (and use .25\pgfdecorationsegmentamplitude as default value).

Second, the key width=1.5\pgfdecorationsegmentamplitude is a check whether the input segment length is smaller or bigger that 1.5\pgfdecorationsegmentamplitude. If it is smaller, it does not draw the circles but just a straight line. I wonder if this is the best choice or it should draw the circles anyway (see MWE).

Third, if one append the key -> in the path, the arrow it is not always drawn, but I can't understand why.

Any help or ideas to solve these issues?

Here's the minimal working example

\documentclass[a4paper]{article}

\usepackage{pgf,pgfsys,pgffor}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
%\usepackage[caption=false]{subfig}
\usepackage{tikz}
\usetikzlibrary{intersections,arrows,decorations.pathmorphing,snakes}


\pgfdeclaredecoration{fiber}{initial}
{
    \state{initial}[width=1.5\pgfdecorationsegmentamplitude, next state=final]{
    \pgfpathmoveto{\pgfpointorigin}
    \pgflineto{\pgfpoint{\pgfdecoratedinputsegmentlength/2}{0pt}}
    \pgfpathcircle{\pgfpoint{\pgfdecoratedinputsegmentlength/2}{.5\pgfdecorationsegmentamplitude}}{.5\pgfdecorationsegmentamplitude}
    \pgfpathcircle{\pgfpoint{\pgfdecoratedinputsegmentlength/2-.25\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}{.5\pgfdecorationsegmentamplitude}
    \pgfpathcircle{\pgfpoint{\pgfdecoratedinputsegmentlength/2+.25\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}{.5\pgfdecorationsegmentamplitude}
    \pgfpathmoveto{\pgfpoint{\pgfdecoratedinputsegmentlength/2}{0pt}}
    }
    \state{final}{
        \pgfpathlineto{\pgfpointdecoratedpathlast}
    }
}

\begin{document}
\begin{tikzpicture}[decoration={fiber, amplitude=1cm}]
\draw[->,decorate] (0, 5mm) -- ++(4,0); % No arrow!
\draw[->,decorate] (0,0)    -- ++(3,0); % No arrow!
\draw[->,decorate] (0,-5mm) -- ++(2,0); % No arrow!
\draw[->,decorate] (0,-1cm) -- ++(1,0); % No circles!
\draw[->,decorate] (0,-1.5cm) -- ++(0.5,0); % No circles!
\end{tikzpicture}

\end{document}
share|improve this question
    
Are they circles or loops like coil decoration? –  percusse Dec 11 '13 at 16:28
    
Do you maybe want a node shape so that it can be used with the circuits family? –  Qrrbrbirlbel Dec 11 '13 at 16:50
    
@percusse They are loops exactly like coil decoration, is it possible to enlarge the coil loops? –  Nicola Dec 11 '13 at 18:27
    
@Qrrbrbirlbel I've never used circuits node, but defining a node could be an idea! I originally thought about define just a decoration style.. –  Nicola Dec 11 '13 at 18:28

1 Answer 1

If you want to write your own coil with tikz (i presume this from your question) you can do it the following way.

The code allows you to set the diameter of the loops and the spacing between the loops. You can reuse this template with custom x,y-position (shift) and scale.

This is a very simple example how you can do it:

\documentclass[a4paper]{article}

\usepackage{tikz}

\begin{document}

% Define size/space
\def\loopsize{1cm}
\def\loopoffset{0.1cm}
% Define the loops
\def\myloops#1#2{
\begin{scope}[shift={#1}, scale=#2]
            % Draw the baseline
    \draw (-1,0) -- (1,0);

        % Draw the loops
    \draw (-\loopoffset,0) node [draw, circle, anchor=south, minimum size=\loopsize] (id) {};
    \draw (0,0) node [draw, circle, anchor=south, minimum size=\loopsize] (id) {};
    \draw (\loopoffset,0) node [draw, circle, anchor=south, minimum size=\loopsize] (id) {};
\end{scope}
}

% Use it in your tikzpicture
\begin{tikzpicture}
    % Insert template at position 0,0 with scale=1
    \myloop{(0,0)}{1}
\end{tikzpicture}
\end{document}

I like to define objects out of tikzpicture-environments to make them reusable. You can put it in your header, etc. and use it easily all over in your document.

I don't know if there is already a library with predefined optical symbols as you need it.

Hope i could help you.

share|improve this answer

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.