summaryrefslogtreecommitdiff
path: root/systems/doc/metapost/source-tutorial/draw.tex
blob: 9ed9b3c1ed08c2a0c6d9a942567d3eae56152710 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
\subsection{The \texttt{draw} command}

The most common command in \MP{} is the |draw| command.  This command is
used to draw paths or pictures.  In order to draw a path from
|z1:=(0,0)| to |z2:=(54,18)| to |z3:=(72,72)|, we should first decide
how we want the path to look.  For example, if we want these points to
simply be connected by line segments, then we use

\begin{lstlisting}[style=MP]
draw z1--z2--z3;
\end{lstlisting}

However, if we want a smooth path between these points, we use

\begin{lstlisting}[style=MP]
draw z1..z2..z3;
\end{lstlisting}

In order to specify the direction of the path at the points, we use the
|dir| operator.  In \autoref{fig:draw1} we see that the smooth path is
horizontal at |z1|, a 45\textdegree\ angle at |z2|, and vertical at
|z3|.  These constraints on the B\'{e}zier curve are imposed by

\begin{lstlisting}[style=MP]
draw z1{right}..z2{dir 45}..{up}z3;
\end{lstlisting}

\begin{figure}
  \begin{withattachment}{draw.mp}
    \centering
    \includegraphics{draw-1.mps}
  \end{withattachment}
  \caption{\texttt{draw} examples}
  \label{fig:draw1}
\end{figure}

Notice that |z2{dir 45}| forces the \textit{outgoing} direction at |z2|
to be 45\textdegree.  This implies an \textit{incoming} direction at
|z2| of 45\textdegree.  In order to require different incoming and
outgoing directions, we would use

\begin{lstlisting}[style=MP]
draw z1{right}..{dir |$\theta_i$|}z2{dir |$\theta_o$|}..{up}z3;
\end{lstlisting}
where $\theta_i$ and $\theta_o$ are the incoming and outgoing
directions, respectively.