% TeXdraw examples

% $Id: txdexamp.tex,v 2.1 2019/03/28 texdraw-V2R0a $

% These examples are taken from the TeXdraw manual.  Note that the fonts
% for text will be different from those in the manual -- here we use the
% plain TeX defaults.

%  Peter Kabal
%  Department of Electrical Engineering
%  McGill University
%  3480 University
%  Montreal, Quebec
%  Canada  H3A 2A7

%  peter dot kabal at mcgill dot ca
 
\input texdraw
\input txdtools
\let\et=\etexdraw
\def\etexdraw{\drawbb\et}

\noindent
TeXdraw examples using plain TeX.

\bigskip
\centertexdraw{
  \avec (0 0.8) \textref h:C v:B \htext (0 0.9){\sl y}
  \move (0 0) \avec (0.8 0) \textref h:L v:C \htext(0.9 0){\sl x}
  \move (0 1.0)}

\bigskip
\centertexdraw{
  \drawdim{cm} \linewd 0.02
  \move(2 2) \lvec(3 3) \lvec(2 4) \lvec(1 3) \lvec(2 2)
  \textref h:C v:C \htext(2 3){$\sum \rho_n$}
}

\bigskip
\centertexdraw{
  \drawdim in
  \linewd 0.03 \setgray 0.6 \arrowheadtype t:F \avec(0.5 0.5)
  \linewd 0.01 \setgray 0   \arrowheadtype t:V \avec(1.0 0.5)
  \linewd 0.015 \lpatt(0.067 0.1) \lvec (1.5 0)
  \linewd 0.02 \lpatt() \arrowheadtype t:T \avec(2.0 0.5)
  \arrowheadtype t:H \avec(2.5 0.5)
  \setgray 0.4 \arrowheadtype t:W \avec(3.0 0)
  \textref h:R v:T \htext (0.35 0.50){\tt t:F}
  \textref h:R v:T \htext (1.0 0.43){\tt t:V}
  \textref h:R v:T \htext (1.82 0.50){\tt t:T}
  \textref h:R v:T \htext (2.5 0.43){\tt t:H}
  \textref h:R v:B \htext (2.8 0){\tt t:W}
}

\bigskip
\centertexdraw{
  \def\bdot {\bsegment
               \fcir f:0 r:0.02
             \esegment}
  \def\Ttext #1{\bsegment
                  \textref h:C v:B \htext (0 +0.06){#1}
                \esegment}
  \def\Btext #1{\bsegment
                  \textref h:C v:T \htext (0 -0.06){#1}
                \esegment}
  \def\Ltext #1{\bsegment
                  \textref h:R v:C \htext (-0.08 0){#1}
                \esegment}
  \def\Rtext #1{\bsegment
                  \textref h:L v:C \htext (+0.08 0){#1}
                \esegment}
  \move (-1.5 0)
  \bsegment
    \move (+1.55 +0.45) \move (-1.55 -0.45) \move (0 0)
    \Ttext{Horizontal Text}
    \bdot                   \Btext{\tt h:C v:C}
    \move (-0.9 0)    \bdot \Ltext{\tt h:L v:C}
    \move (+0.9 0)    \bdot \Rtext{\tt h:R v:C}
    \move (0 +0.3)    \bdot \Ttext{\tt h:C v:T}
    \move (0 -0.3)    \bdot \Btext{\tt h:C v:B}
    \move (-0.9 -0.3) \bdot \Ltext{\tt h:L v:B}
    \lvec (-0.9 +0.3) \bdot \Ltext{\tt h:L v:T}
    \lvec (+0.9 +0.3) \bdot \Rtext{\tt h:R v:T}
    \lvec (+0.9 -0.3) \bdot \Rtext{\tt h:R v:B}
    \lvec (-0.9 -0.3)
  \esegment
  \def\atext {\rtext td:45 }
  \def\ATtext #1{\bsegment
                   \setsegscale 0.707
                   \textref h:C v:B \atext (-0.06 +0.06){#1}
                 \esegment}
  \def\ABtext #1{\bsegment
                   \setsegscale 0.707
                   \textref h:C v:T \atext (+0.060 -0.06){#1}
                 \esegment}
  \def\ALtext #1{\bsegment
                   \setsegscale 0.707
                   \textref h:R v:C \atext (-0.08 -0.08){#1}
                 \esegment}
  \def\ARtext #1{\bsegment
                   \setsegscale 0.707
                   \textref h:L v:C \atext (+0.08 +0.08){#1}
                 \esegment}
  \move (+1.5 0)
  \bsegment
    \move (+1.33 +1.33) \move (-1.33 -1.33) \move (0 0)
    \setsegscale 0.707
    \ATtext{Rotated Text}
    \bdot                   \ABtext{\tt h:C v:C}
    \move (-0.9 -0.9) \bdot \ALtext{\tt h:L v:C}
    \move (+0.9 +0.9) \bdot \ARtext{\tt h:R v:C}
    \move (-0.3 +0.3) \bdot \ATtext{\tt h:C v:T}
    \move (+0.3 -0.3) \bdot \ABtext{\tt h:C v:B}
    \move (-0.6 -1.2) \bdot \ALtext{\tt h:L v:B}
    \lvec (-1.2 -0.6) \bdot \ALtext{\tt h:L v:T}
    \lvec (+0.6 +1.2) \bdot \ARtext{\tt h:R v:T}
    \lvec (+1.2 +0.6) \bdot \ARtext{\tt h:R v:B}
    \lvec (-0.6 -1.2)
  \esegment
}

\vfill
\eject


\bigskip
\centertexdraw{
  \move(-0.75 -0.25) \lvec (-0.75 +0.5) \lvec (+0.75 +0.5)
  \lvec(+0.75 -0.25) \ifill f:0.9         % fill the region
  \move(0 0)
             \avec(-0.75 -0.25) \textref h:R v:C \htext{H-text}
  \move(0 0) \avec(-0.75 +0.25) \textref h:R v:B \htext{H-text}
  \move(0 0) \avec(0 +0.5)      \textref h:L v:T \vtext{V-text}
  \move(0 0) \avec(+0.75 +0.25) \textref h:L v:B \htext{H-text}
  \move(0 0) \avec(+0.75 -0.25) \textref h:L v:C \htext{H-text}
  \move (-1.15 -0.3) \move (+1.15 +0.92)  % increase the size of the drawing
}

\bigskip
\centertexdraw{
  \linewd 0.02
  \fcir f:0.7 r:1
  \larc r:1 sd:45 ed:135
  \lvec ( 0.707  0.707) \move (0 0) \lvec (-0.707 +0.707)
}

\bigskip
\centertexdraw{
  \def\Ltext #1{\bsegment
                  \textref h:R v:C \htext (-0.08 0){#1}
                \esegment}
  \def\Rtext #1{\bsegment
                  \textref h:L v:C \htext (+0.08 0){#1}
                \esegment}
  \def\bdot {\fcir f:0 r:0.02 }
  \def\Ldot #1{\bdot \Ltext{#1}}
  \def\Rdot #1{\bdot \Rtext{#1}}
  \move (-2 0)
  \bsegment
    \lpatt (0.033)
    \move (0 0) \Ldot{0} \lvec (0 1) \Ldot{1}
    \lvec (1 1) \Rdot{2} \lvec (1 0) \Rdot{3}
    \lpatt ()
    \move (0 0) \clvec (0 1)(1 1)(1 0)
  \esegment
  \move (0 0)
  \bsegment
    \lpatt (0.033)
    \move (0 0) \Ldot{0}  \lvec (0.5 0.8) \Ldot{1}
    \lvec (1.5 0.8) \Rdot{2} \lvec (1 0) \Rdot{3}
    \lpatt ()
    \move (0 0) \clvec (0.5 1)(1.5 1)(1 0)
  \esegment
  \move ( 2 0)
  \bsegment
    \lpatt (0.033)
    \move (0 0) \Ldot{0} \lvec (0 1) \Ldot{1}
    \lvec (1 0) \Rdot{2} \lvec (1 1) \Rdot{3}
    \lpatt ()
    \move (0 0) \clvec (0 1)(1 0)(1 1)
  \esegment
}

\bigskip
\centertexdraw{
\move (0.5 0)
\lvec (0 0.5) \clvec (0.5 0.85)(1 0.65)(1.5 1)
\lvec (2 0.5) \clvec (1.5 0.15)(1 0.35)(0.5 0)
\lfill f:0.8
}

\vfill
\eject


\bigskip
\def\tbox #1{\bsegment
               \lvec (0 +0.25)    \lvec (0.75 +0.25)
               \lvec (0.75 -0.25) \lvec (0 -0.25) \lvec (0 0)
               \textref h:C v:C \htext (0.375 0){#1}
               \savepos (0.75 0)(*ex *ey)
             \esegment
             \move (*ex *ey)}
\centertexdraw{
  \ravec (1 0) \tbox{$H(z)$} \ravec (1 0)
}

\bigskip
\def\cavec (#1 #2)(#3 #4)(#5 #6){
  \clvec (#1 #2)(#3 #4)(#5 #6)
  \cossin (#3 #4)(#5 #6)\cosa\sina
  \rmove (0 0) % stroke the Bezier curve
  \bsegment
    \drawdim in \setsegscale 0.05
    \move ({-\cosa} -\sina)  \avec (0 0)
  \esegment}

\def\caw (#1 #2){
  \currentpos \xa\ya
  \cossin ({\xa} \ya)(#1 #2)\cosa\sina

% The nominal wiggly curve is (0 0) (1+dx dy) (-dx -dy) (1 0)
% Find the rotated offset (dx dy) -> (du dv)
  \rotatecoord (0.4 0.1)\cosa\sina \du\dv

% calculate the length of the vector
  \vectlen ({\xa} \ya)(#1 #2)\len

% draw the curve in normalized units
  \bsegment
    \setsegscale {\len}
    \realadd \cosa \du \tmpa  \realadd \sina \dv \tmpb
    \cavec ({\tmpa} \tmpb)({-\du} -\dv)({\cosa} \sina)
  \esegment

  \move (#1 #2)}

% rotate a coordinate (x y)
% arguments: (x y) cosa sina x' y'
%  x' = cosa * x - sina * y;  y' = sina * x + cosa * y
\def\rotatecoord (#1 #2)#3#4#5#6{
  \getpos (#1 #2)\xarg\yarg
  \realmult \xarg {#3} \tmpa  \realmult \yarg {#4} \tmpb
  \realadd \tmpa {-\tmpb} #5
  \realmult \xarg {#4} \tmpa  \realmult \yarg {#3} \tmpb
  \realadd \tmpa \tmpb #6}

\centertexdraw{
  \arrowheadtype t:W
  \move (0 0)
  \cavec (1.4 0.1)(-0.4 -0.1)(1 0)
  \move (1 0) \caw (1 1) \htext{tip at \tt (1 1)}
  \move (1 0) \caw (2 1) \htext{tip at \tt (2 1)}
  \move (1 0) \caw (2 0) \htext{tip at \tt (2 0)}
  \move (0 1.13) \move (0 -0.04)
}

\vfill
\eject


\bigskip
\def\delay {\bsegment
              \setsegscale 0.3
              \lvec (0 +0.5) \lvec (1 +0.5) \lvec (1 -0.5)
              \lvec (0 -0.5) \lvec (0 0)
              \textref h:C v:C  \htext (0.5 0){$z^{-1}$}
              \savepos (1 0)(*ex *ey)
            \esegment
            \move (*ex *ey)}
\def\bdot {\fcir f:0 r:0.02 }
\def\Ttext #1{\bsegment
                \textref h:C v:B  \htext (0 +0.06){#1}
              \esegment}
\def\Btext #1{\bsegment
                \textref h:C v:T  \htext (0 -0.06){#1}
              \esegment}
\def\Ltext #1{\bsegment
                \textref h:R v:C  \htext (-0.06 0){#1}
              \esegment}
\def\Rtext #1{\bsegment
                \textref h:L v:C  \htext (+0.06 0){#1}
              \esegment}
\def\cradius {0.08}
\def\pluss {\bsegment
              \setsegscale {\cradius}
              \move (-0.5 0) \lvec (+0.5 0)
              \move (0 -0.5) \lvec (0 +0.5)
            \esegment}
\def\pcir {\lcir r:{\cradius} \pluss}
\def\puttext (#1 #2)#3{\bsegment
                         \setsegscale {\cradius}
                         \textref h:C v:C \htext (#1 #2){#3}
                       \esegment}
\def\putwnw #1{\puttext (-1.7 +1.2){#1}}
\def\putwsw #1{\puttext (-1.7 -1.2){#1}}
\def\putn   #1{\puttext ( 0   +2  ){#1}}
\def\puts   #1{\puttext ( 0   -2  ){#1}}
\def\avectoc (#1 #2){\currentpos \xa\ya
                     \cossin ({\xa} \ya)(#1 #2)\cosa\sina
                     \savepos (#1 #2)(*tx *ty)
                     \bsegment
                       \move (*tx *ty)
                       \setsegscale {\cradius}
                       \rmove ({-\cosa} -\sina)
                       \savecurrpos (*ex *ey)
                     \esegment
                     \avec (*ex *ey)
                     \move (#1 #2)}
\def\avecfrc (#1 #2){\currentpos \xa\ya
                     \cossin ({\xa} \ya)(#1 #2)\cosa\sina
                     \bsegment
                       \setsegscale {\cradius}
                       \move ({\cosa} \sina)
                       \savecurrpos (*ex *ey)
                     \esegment
                     \move (*ex *ey)
                     \avec (#1 #2)}

\centertexdraw{
\drawdim in
\arrowheadtype t:F  \arrowheadsize l:0.08 w:0.04
\def\pl {$\scriptscriptstyle +$} \def\mn {$\scriptscriptstyle -$}

\move (0 +0.63) \move (0 -0.60) \move (0 0) % compensate for the text size

% Input to the first stage
\bsegment
  \Ltext{$x(n)$}
  \lvec (0.3 0) \bdot \lvec (0.3 +0.4)
  \move (0.3 0) \lvec (0.3 -0.4)
  \savepos (0.3 0)(*ex *ey)
\esegment
\move (*ex *ey)

% first lattice stage
\bsegment
  \move (0 +0.4)  \avectoc (1.7 +0.4)
  \pcir \putwnw{\pl} \puts{\mn}
  \avecfrc (2.1 +0.4)
  \move (0 -0.4)  \avec (0.4 -0.4) \delay \avectoc (1.7 -0.4)
  \pcir \putwsw{\pl} \putn{\mn}
  \avecfrc (2.1 -0.4)
  \move (0.9 +0.4)  \bdot  \avectoc (1.7 -0.4)
  \move (0.9 -0.4)  \bdot  \avectoc (1.7 +0.4)
  \move (0.1 +0.42) \Ttext {$f_0(n)$}
  \move (2.0 +0.42) \Ttext {$f_1(n)$}
  \move (0.1 -0.4)  \Btext {$b_0(n)$}
  \move (2.0 -0.4)  \Btext {$b_1(n)$}
  \textref h:L v:B  \htext (1.15 +0.2){$K_1$}
  \textref h:L v:T  \htext (1.15 -0.2){$K_1$}
  \savepos (2.1 0)(*ex *ey)
\esegment
\move (*ex *ey)

% center section
\bsegment
  \textref h:C v:C
  \htext (0.3 +0.4){$\cdots$}
  \htext (0.3 -0.4){$\cdots$}
  \savepos (0.6 0)(*ex *ey)
\esegment
\move (*ex *ey)

% last lattice stage
\bsegment
  \move (0 +0.4)  \avectoc (1.7 +0.4)
  \pcir \putwnw{\pl} \puts{\mn}
  \avecfrc (2.3 +0.4) \Rtext{$e(n)$}
  \move (0 -0.4)  \avec (0.4 -0.4) \delay \avectoc (1.7 -0.4)
  \pcir \putwsw{\pl} \putn{\mn}
  \avecfrc (2.1 -0.4)
  \move (0.9 +0.4)  \bdot  \avectoc (1.7 -0.4)
  \move (0.9 -0.4)  \bdot  \avectoc (1.7 +0.4)
  \move (0.1 +0.42) \Ttext {$f_{P-1}(n)$}
  \move (2.0 +0.42) \Ttext {$f_P(n)$}
  \move (0.1 -0.4)  \Btext {$b_{P-1}(n)$}
  \move (2.0 -0.4)  \Btext {$b_P(n)$}
  \textref h:L v:B  \htext (1.15 +0.2){$K_P$}
  \textref h:L v:T  \htext (1.15 -0.2){$K_P$}
\esegment
}

\bigskip
\centertexdraw{
\arrowheadtype t:F  \arrowheadsize l:0.08 w:0.04
\def\ds {\displaystyle}
\def\ticklab (#1 #2)#3{\move(#1 #2)
                       \bsegment
                         \lvec (0 0.05)
                         \textref h:C v:T \htext (0 -0.05){#3}
                       \esegment}
\def\Rtext #1{\bsegment
                \textref h:L v:C \htext ( 0.08 0){#1}
              \esegment}

\move (2.4 -0.32)    % move to set the size

\move (0 0)
% Axes
\avec (0  1.4)
\move (0 0) \avec (2.2 0) \Rtext{$\omega$}
\ticklab (0 0)   {0}
\ticklab (0.8 0) {$\ds {\pi \over  2N} $}
\ticklab (1.2 0) {$\omega_s$}
\ticklab (1.6 0) {$\ds {\pi \over N} $}

\linewd 0.025
\move (0 1)
\lvec (0.4 1)
\lvec (0.44 0.998)
\lvec (0.48 0.988)
\lvec (0.52 0.973)
\lvec (0.56 0.951)
\lvec (0.60 0.923)
\lvec (0.64 0.891)
\lvec (0.68 0.852)
\lvec (0.72 0.809)
\lvec (0.76 0.760)
\lvec (0.80 0.707)
\lvec (0.84 0.649)
\lvec (0.88 0.587)
\lvec (0.92 0.522)
\lvec (0.96 0.454)
\lvec (1.00 0.382)
\lvec (1.04 0.309)
\lvec (1.08 0.233)
\lvec (1.12 0.156)
\lvec (1.16 0.078)
\lvec (1.20 0)
\lvec (1.9 0)
}

\bigskip
\centertexdraw{
\arrowheadtype t:V \arrowheadsize l:0.08 w:0.04
\linewd 0.01
\setunitscale 1.5            % circle will have radius 1.5 inches

\def\Btext #1{\bsegment
                \textref h:C v:T \htext (0 -0.04){#1}
              \esegment}
\def\Ttext #1{\bsegment
                \textref h:C v:B \htext (0  0.04){#1}
              \esegment}
\def\Ltext #1{\bsegment
                \textref h:R v:C \htext (-0.04 0){#1}
              \esegment}
\def\bdot {\fcir f:0 r:0.0133 }
\def\vtick {\bsegment
              \move (0 -0.05) \lvec (0  0.05)
            \esegment}
\def\htick {\bsegment
              \move (-0.05 0) \lvec ( 0.05 0)
            \esegment}
\def\Hlen #1#2{\bsegment
                 \vtick \avec ({#1} 0) \vtick \avec (0 0)
                 \relsegscale 0.5
                 \move ({#1} 0) \Ttext {#2}
               \esegment}
\def\Vlen #1#2{\bsegment
                 \htick \avec (0 {#1}) \htick \avec (0 0)
                 \relsegscale 0.5
                 \move (0 {#1}) \Ltext {#2}
               \esegment}

\lcir r:1                         % circle
\move (-1.05 0) \lvec ( 1.05 0)   % axes
\move (0 -1.05) \lvec (0  1.05)

\move (0 0) \lvec (0.707 0.707) \bdot
\rmove (0.02 0.02) \textref h:L v:B \htext {X}
\move (0.707 -0.707) \bdot
\textref h:R v:T \htext(-0.02 -0.02){O}

\move (0.5 0)                     % center of ellipse
\bsegment
  \lellip rx:0.435 ry:0.804
  \bdot \Btext {$\beta_2$}
  \move (0 0.15) \Hlen {0.435}{$|\beta_1{+}\beta_3|$}
  \move (-0.7 0) \Vlen {0.804}{$|\beta_1{-}\beta_3|$}
\esegment
}

\bye
