internal files should be opened as bytes as well
[PyX.git] / design / boxalign.tex
blob333e159caeabc606807de5820259ef22d9fe6733
1 % $Header$
3 \documentclass{article}
4 \usepackage{pyx,graphicx}
5 \begin{document}
6 \noindent\textbf{\huge Relative box alignment}\medskip
7 \section{Introduction}
8 The relative alignment of boxes is an important part in many drawing
9 tasks. At the moment the main focus is the flexible alignment of text,
10 because it is an essential ingredience for the drawing of axes in the
11 graph module. Therefore, the implementation is part of the graph
12 module at the moment, but the alignment of any kind of boxes is
13 expected be become of general interest in the future. Later on it will
14 certainly become a module for itself. Alternatively the alignment
15 techniques might become a feature of path elements, which sounds quite
16 sophisticated but it might turn out to be inadequate.
18 We consider boxes to be two dimensional convex polygons. We may
19 introduce round corners and other goodies later on, but for the moment
20 polygons are everything we are in need for.
22 The relative alignment takes place respecting an alignment vector
23 $\vec a$. The box has a reference point $\vec c$, which can be placed
24 anywhere within the polygon. Otherwise some alignment requests might
25 fail or result in unexpected alignments. An alignment request has to
26 calculate a translation vector $\vec t$ so that the reference point is
27 on the line defined by the alignment vector.
28 \begin{equation}
29 \label{eq:center}
30 \alpha\vec a=\vec c+\vec t
31 \end{equation}
32 The alignment vector $\vec a$ is described by a normalized direction
33 vector, which is provided as a tuple \verb|(dx, dy)| to the alignment
34 routine. The absolute value of the alignment vector is given by
35 \verb|a| and might be zero or even negative. The distance of the box
36 is calculated out of the alignment vector so that an additional
37 alignment condition is met.
39 The task of box alignment is splitted into the task of aligning a line
40 segment (a segment of the polygon). The polygon and thus the line
41 segments are considered to be vectored in mathematically positive
42 orientation. Thus the alignment request for a line segment predefines
43 a half space. It might happen, that the alignment of a line segment
44 is restrained by the finite length of the segment in that way, that
45 the alignment should take place based on an end point of the line
46 segment. When this happens for the end point of a line segment and a
47 starting of the following line segment, this very point has to be
48 considered for the alignment.
50 \pagebreak
51 \section{Alignment Primitives}
52 \subsection{Align a point relative to a tangent}
53 The point $\vec p$ should be aligned at the dotted line:
55 \centerline{\includegraphics{boxalignpal}}
57 We introduce the normalized tangential vector $\vec b$ to the
58 alignment vector $\vec a$, $\vec b\perp\vec a$.
60 The solution is defined by equation~(\ref{eq:center}) and
61 \begin{equation}
62 \vec a+\beta\vec b=\vec p+\vec t\,.
63 \end{equation}
65 \subsection{Align a line segment relative to a tangent}
66 The line segment has to be perpendicular to the alignment vector.
67 We can than continue as in section \ref{s:calignline}. However, if the
68 line segment is not perpendicular to the alignment vector, the
69 starting point or end point of the line segment (whichever is closer
70 in terms of the aligment direction) should be considered for the
71 alignment.
73 \subsection{Align a point relative to a circle}
74 The point $\vec p$ should be aligned at the dotted circle:
76 \centerline{\includegraphics{boxalignpac}}
78 The solution is defined by equation~(\ref{eq:center}) and
79 \begin{equation}
80 |\vec a|=|\vec p+\vec t|\,.
81 \end{equation}
83 \subsection{Align a line segment relative to a circle}
84 \label{s:calignline}
85 The line segment between the points $\vec e$ and $\vec f$ should have
86 a single point of contact with the dotted circle:
88 \centerline{\includegraphics{boxalignlac}}
90 We introduce $\vec g=\vec e-\vec f$. Thus the line segment is
91 described by $\vec e-\beta \vec g$ for $\beta=[0;1]$. We introduce the
92 vector $\vec b$ and ask for $\vec b\perp\vec g$. Therefore $\vec b$ is
93 the contract point and it can be calculated by
94 \begin{equation}
95 \vec b=|\vec a|\frac{\vec a-\frac{\vec a\vec g}{\vec g\vec g}\vec g}
96 {\left|\vec a-\frac{\vec a\vec g}{\vec g\vec g}\vec g\right|}\,.
97 \end{equation}
98 We can neglect solutions where the z-component of $\vec b\times\vec g$
99 is negative in order to restrict the solution to a half space.
101 The solution is defined by equation~(\ref{eq:center}) and
102 \begin{equation}
103 \vec b=\vec e-\beta\vec g+\vec t\,.
104 \end{equation}
106 The solution has to fullfill the condition $\beta=[0;1]$, otherwise
107 the starting point ($\beta<0$) or end point ($\beta>1$) of the line
108 segment should be considered for the alignment.
110 \section{Examples}
111 \includegraphics{boxalignexample}
113 \end{document}