Voltage arrow

View: New views
3 Messages — Rating Filter:   Alert me  

Voltage arrow

by Christophe Jorssen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I'm trying to adapt some Mark Wibrow's code that he gave here and on
fr.comp.text.tex to draw voltage arrows. I defined a Voltage> style
(with two arguments).

I'd like to be able to say

\draw[Voltage>={.7cm}{$u$}] (A) -- (B);

and the arrow drawn would be risen of .7cm and have a label $u$, and
start after A and stop before B, something like that (ascii art).
        u
   --------->
     ------
A---|    |---B
     ------

I tried the following code, but

1) the line is not risen
2) the arrow is not correctly drawn.

Any ideas ?

In addition, I think that the syntax of the Voltage> is not as clear as
usual in tikz. Do you have other ideas ?

BTW, this is the french way of doing this. I did not find any IEC
recommendations to do that. Do you know if this is IEC compliant?

Thanks in advance

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{decorations}
\usetikzlibrary{decorations.markings}

\pgfdeclaredecoration{single line}{initial}{%
   \state{initial}[width=\pgfdecoratedpathlength-1sp]{%
     \pgfpathmoveto{\pgfpointorigin}}
   \state{final}{\pgfpathlineto{\pgfpointorigin}}
}
\tikzset{%
   raise line/.style={%
     decoration = {single line, raise=#1},
     decorate},
   shorten risen line/.style args={shorten by #1 and #2 risen by #3}{%
     decoration = {%
       single line,
       raise = #3,
       pre = moveto,
       pre length = {#1*\pgfmetadecoratedpathlength},
       post = moveto,
       post length = {#2*\pgfmetadecoratedpathlength}},
    decorate},
   label line/.style={%
     postaction = {%
       decoration = {raise=0pt,markings,mark=#1},
       decorate}},
   Voltage>/.style 2 args={%
     ->,
     shorten risen line = shorten by .1 and .1 risen by #1,
     label line = {at position .5 with {\node[above]{#2};}}}
}

\begin{document}

\begin{tikzpicture}
   \coordinate[pin=below:$A$] (A) at (0,0);
   \coordinate[pin=below:$B$] (B) at (3,3);
   \draw[Voltage>={.7cm}{$u$}] (A) -- (B);
\end{tikzpicture}

\end{document}

--
Christophe

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

Re: Voltage arrow

by Mark Wibrow-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Tricky one this. It seems that when you use pre and post stuff in the
decoration this uses a special internal meta-decoration which doesn't
like the raise key. It could be possible to hack into this internal
meta-decoration, or rewrite the single line decoration to make it more
sophisticated and enable shortening the line.

However, a much cleaner, quicker solution (if you don't mind switching
to specifying actual lengths instead of fractions of the length of the
line) is to use the tikz keys shorten > and shorten < to get the
desired effect:

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{decorations}
\usetikzlibrary{decorations.markings}

\pgfdeclaredecoration{single line}{initial}{%
  \state{initial}[width=\pgfdecoratedpathlength-1sp]{%
    \pgfpathmoveto{\pgfpointorigin}}
  \state{final}{\pgfpathlineto{\pgfpointorigin}}
}

\tikzset{%
  raise line/.style={%
    decoration = {single line, raise=#1},
    decorate},
  shorten risen line/.style args={shorten by #1 and #2 risen by #3}{%
    decoration = {%
      single line,
      raise = #3
   },
   decorate,
   shorten <=#1,
   shorten >=#2},
  label line/.style={%
    postaction = {%
      decoration = {raise=0pt,markings,mark=#1},
      decorate}},
  Voltage>/.style 2 args={%
    ->,
    shorten risen line = shorten by 0.5cm and 0.5cm risen by #1,
    label line = {at position .5 with {\node[above]{#2};}}}
}

\begin{document}

\begin{tikzpicture}
  \coordinate[pin=below:$A$] (A) at (0,0);
  \coordinate[pin=below:$B$] (B) at (3,3);
  \draw[Voltage>={.7cm}{$u$}] (A) -- (B);
\end{tikzpicture}

\end{document}


Hope this helps

Mark
2009/10/6 Christophe Jorssen <jorssen.leraincy@...>:

> Hello,
>
> I'm trying to adapt some Mark Wibrow's code that he gave here and on
> fr.comp.text.tex to draw voltage arrows. I defined a Voltage> style
> (with two arguments).
>
> I'd like to be able to say
>
> \draw[Voltage>={.7cm}{$u$}] (A) -- (B);
>
> and the arrow drawn would be risen of .7cm and have a label $u$, and
> start after A and stop before B, something like that (ascii art).
>        u
>   --------->
>     ------
> A---|    |---B
>     ------
>
> I tried the following code, but
>
> 1) the line is not risen
> 2) the arrow is not correctly drawn.
>
> Any ideas ?
>
> In addition, I think that the syntax of the Voltage> is not as clear as
> usual in tikz. Do you have other ideas ?
>
> BTW, this is the french way of doing this. I did not find any IEC
> recommendations to do that. Do you know if this is IEC compliant?
>
> Thanks in advance
>
> \documentclass{minimal}
>
> \usepackage{tikz}
> \usetikzlibrary{decorations}
> \usetikzlibrary{decorations.markings}
>
> \pgfdeclaredecoration{single line}{initial}{%
>   \state{initial}[width=\pgfdecoratedpathlength-1sp]{%
>     \pgfpathmoveto{\pgfpointorigin}}
>   \state{final}{\pgfpathlineto{\pgfpointorigin}}
> }
> \tikzset{%
>   raise line/.style={%
>     decoration = {single line, raise=#1},
>     decorate},
>   shorten risen line/.style args={shorten by #1 and #2 risen by #3}{%
>     decoration = {%
>       single line,
>       raise = #3,
>       pre = moveto,
>       pre length = {#1*\pgfmetadecoratedpathlength},
>       post = moveto,
>       post length = {#2*\pgfmetadecoratedpathlength}},
>    decorate},
>   label line/.style={%
>     postaction = {%
>       decoration = {raise=0pt,markings,mark=#1},
>       decorate}},
>   Voltage>/.style 2 args={%
>     ->,
>     shorten risen line = shorten by .1 and .1 risen by #1,
>     label line = {at position .5 with {\node[above]{#2};}}}
> }
>
> \begin{document}
>
> \begin{tikzpicture}
>   \coordinate[pin=below:$A$] (A) at (0,0);
>   \coordinate[pin=below:$B$] (B) at (3,3);
>   \draw[Voltage>={.7cm}{$u$}] (A) -- (B);
> \end{tikzpicture}
>
> \end{document}
>
> --
> Christophe
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry® Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9-12, 2009. Register now!
> http://p.sf.net/sfu/devconf
> _______________________________________________
> pgf-users mailing list
> pgf-users@...
> https://lists.sourceforge.net/lists/listinfo/pgf-users
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

Re: Voltage arrow

by Christophe Jorssen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Mark Wibrow a écrit :
> Hi,
>
> Tricky one this. It seems that when you use pre and post stuff in the
> decoration this uses a special internal meta-decoration which doesn't
> like the raise key. It could be possible to hack into this internal
> meta-decoration, or rewrite the single line decoration to make it more
> sophisticated and enable shortening the line.

I see ;-)

>
> However, a much cleaner, quicker solution (if you don't mind switching
> to specifying actual lengths instead of fractions of the length of the
> line) is to use the tikz keys shorten > and shorten < to get the
> desired effect:

Thanks very much Mark. This does the trick.

--
Christophe

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users