\newpage

\section{Class \Iclass{vector}} % (fold)
\label{sec:class_vector}

In fact, they are more a class of oriented segments than vectors in the strict mathematical sense.

A vector is defined by giving two points (i.e. two affixes). 
|V.AB = vector : new (z.A,z.B)| creates the vector $\overrightarrow(AB)$, i.e. the oriented segment with origin $A$ representing a vector. A few rudimentary operations are defined, such as sum, subtraction and multiplication by a scalar.

The sum is defined as follows:

Let V.AB + V.CD result in a vector V.AE defined as follows

If $\overrightarrow{CD} = \overrightarrow{BE} $ then $\overrightarrow{AB} + \overrightarrow{CD} = \overrightarrow{AB} + \overrightarrow{BE} =\overrightarrow(AE)$

\begin{mybox}
   Creation |V.AB = vector: new (z.A,z.B)|
\end{mybox}

\begin{verbatim}
z.A = ...
z.B = ...
z.C = ...
z.D = ...
V.AB = vector : new (z.A,z.B)
V.CD = vector : new (z.C,z.D)
V.AE = V.AB + V.CD  -- possible V.AB : add (V.CD)
z.E  = V.AE.h -- we recover the final point (h = head)
\end{verbatim}

\subsection{Attributes of a vector} % (fold)
\label{sub:attributes_of_a_vector}

% subsection attributes_of_a_vector (end)
\vspace{1em}
\bgroup
\small
\catcode`_=12
\captionof{table}{Vector attributes.}\label{vector:att}  
\begin{tabular}{lll}
\toprule
\textbf{Attributes}      & \textbf{Application}& \textbf{Example}\\
\Iattr{vector}{pa}       &  |V.AB.t = z.A| t for tail   & see (\ref{ssub:methods}) \\
\Iattr{vector}{pb}       &  |V.AB.h = z.B| h for head   & see (\ref{ssub:methods})  \\
\Iattr{vector}{type}     &  |V.AB.type = 'vector'|  & \\  
\Iattr{vector}{slope}    &  |V.AB.slope| & see (\ref{ssub:example_vector_attributes})\\
\Iattr{vector}{length}   &  |V.AB.norm|& see (\ref{ssub:example_vector_attributes})\\
\bottomrule
\end{tabular}
\egroup

\subsubsection{Example vector attributes} % (fold)
\label{ssub:example_vector_attributes}

\begin{minipage}{.6\textwidth}
  \begin{verbatim}
    \begin{tkzelements} 
      z.O         = point: new (0,0)
      z.A         = point: new (0,1)
      z.B         = point: new (3,4)
      L.AB        = line : new ( z.A , z.B )
      z.C         = point: new (1,2)
      z.D         = point: new (2,1)
      u           = vector : new (z.A,z.B)
      v           = vector : new (z.C,z.D)
      w =u+v
      z.E = w.h
  \end{tkzelements}
  \begin{tikzpicture}[gridded]
      \tkzGetNodes
      \tkzLabelPoints(A,B,C,D,O,E)
      \tkzDrawSegments[->,red](A,B C,D A,E)
      \tkzLabelSegment(A,B){$\overrightarrow{u}$}
      \tkzLabelSegment(C,D){$\overrightarrow{v}$}
      \tkzLabelSegment(A,E){$\overrightarrow{w}$}
    \end{tikzpicture}
  $\overrightarrow{w}$ has slope :
  $\tkzDN{\tkzUseLua{math.deg(w.slope)}}^\circ$
  \end{verbatim}
\end{minipage}
\begin{minipage}{.4\textwidth}
\begin{tkzelements} 
  z.O         = point: new (0,0)
  z.A         = point: new (0,1)
  z.B         = point: new (3,4)
  L.AB        = line : new ( z.A , z.B )
  z.C         = point: new (1,2)
  z.D         = point: new (2,1)
  u           = vector : new (z.A,z.B)
  v           = vector : new (z.C,z.D)
  w           = u+v
  z.E         = w.h
\end{tkzelements}
\begin{tikzpicture}[gridded]
  \tkzGetNodes
  \tkzLabelPoints(A,B,C,D,O,E)
  \tkzDrawSegments[->,red](A,B C,D A,E)
  \tkzLabelSegment(A,B){$\overrightarrow{u}$}
  \tkzLabelSegment(C,D){$\overrightarrow{v}$}
  \tkzLabelSegment(A,E){$\overrightarrow{w}$}
\end{tikzpicture}

$\overrightarrow{w}$ has slope :
$\tkzDN{\tkzUseLua{math.deg(w.slope)}}^\circ$
\end{minipage}
% subsubsection example_vector_attributes (end)

\subsection{Methods of the class vector} % (fold)
\label{sub:methods_of_the_class_vector}

\vspace{1em}
\bgroup
\catcode`_=12
\small
\captionof{table}{Methods of the class vector.}\label{vector:met}
\begin{tabular}{lll}
\toprule
 \textbf{Metamethods} & \textbf{Application}& \\
 \midrule
\Imeth{vector}{\_\_add (u,v)}  & |V.AB + V.CD| & \\
\Imeth{vector}{\_\_sub (u,v)}  & |V.AB - V.CD| & \\
\Imeth{vector}{\_\_unm (u)}  & |V.CD = -V.AB| & \\
\Imeth{vector}{\_\_mul (k,u)}  & |V.CD = k*V.AB| & \\
 \midrule
 \textbf{Methods} & \textbf{Application}& \\
\Imeth{vector}{new(pt, pt)}    & |V.AB = vector: new (z.A,z.B) | &  \\
\Imeth{vector}{normalize(V)}    & |V.AB : normalize () | &  \\
\Imeth{vector}{orthogonal(d)}    & |V.AB : orthogonal (d) | &  \\
\Imeth{vector}{scale(d)}    & |V.CD = V.AB : scale (2) | &  $\overrightarrow{CD} = 2\overrightarrow{AB} $ \\
\Imeth{vector}{at (V)}    & |V.DB = V.AC : at (z.D) | & $\overrightarrow{DB} = \overrightarrow{AC} $ \\    
\bottomrule 
\end{tabular}
\egroup

\subsubsection{Example of methods} % (fold)
\label{ssub:example_of_methods}

\begin{minipage}{.5\textwidth}
  \begin{verbatim}
  \begin{tkzelements} 
    z.O         = point: new (0,0)
    z.A         = point: new (0,1)
    z.B         = point: new (3,4)
    V.AB        = vector: new (z.A,z.B)
    V.AC        = V.AB : scale (.5)
    z.C         = V.AC.h
    V.AD        = V.AB : orthogonal ()
    z.D         = V.AD.h
    V.AN        = V.AB : normalize ()
    z.N         = V.AN.h
    V.AR        = V.AB : orthogonal (2*math.sqrt(2))
    z.R         = V.AR.h
    V.AX        = 2*V.AC - V.AR
    z.X         = V.AX.h
    V.OY        = V.AX : at (z.O)
    z.Y         = V.OY.h
  \end{tkzelements}
  \begin{tikzpicture}[gridded]
    \tkzGetNodes
    \tkzDrawSegments[>=stealth,->,red](A,B A,C A,D A,N A,R A,X O,Y)
    \tkzLabelPoints(A,B,C,D,O,N,R,X,Y)
  \end{tikzpicture}
  \end{verbatim}
\end{minipage}
\begin{minipage}{.5\textwidth}
  \begin{tkzelements} 
    z.O         = point: new (0,0)
    z.A         = point: new (0,1)
    z.B         = point: new (3,4)
    V.AB        = vector: new (z.A,z.B)
    V.AC        = V.AB : scale (.5)
    z.C         = V.AC.h
    V.AD        = V.AB : orthogonal ()
    z.D         = V.AD.h
    V.AN        = V.AB : normalize ()
    z.N         = V.AN.h
    V.AR        = V.AB : orthogonal (2*math.sqrt(2))
    z.R         = V.AR.h
    V.AX        = 2*V.AC - V.AR
    z.X         = V.AX.h
    V.OY        = V.AX : at (z.O)
    z.Y         = V.OY.h
  \end{tkzelements}
  \begin{tikzpicture}[gridded]
    \tkzGetNodes
    \tkzDrawSegments[>=stealth,->,red](A,B A,C A,D A,N A,R A,X O,Y)
    \tkzLabelPoints(A,B,C,D,O,N,R,X,Y)
  \end{tikzpicture}
\end{minipage}
% subsubsection example_of_methods (end)
% section class_vector (end)
\endinput