\section{The camera calibration problem}
\label{sec:teo-calibration}
The \textit{geometric camera calibration} is a process that allows to determine all the parameters introduced with the Equation \ref{eq:perspective_projection}. When we calibrate a single camera, we are determining only its intrinsic parameters, instead if we calibrate a couple of cameras (or, as in this case, a laser-camera pair) we are able to locate the points in the 3D space, and we can determine the extrinsic parameters of the equation. Accordingly with what we said in Subsection \ref{subsec:lenses}, lens distortions are critic when we need to reconstruct the 3D world from an image, so they have to be considered by calibration algorithms that, generally, implement non-linear optimization methods (note that the general model for lens distortions is non-linear). Furthermore, some algorithms (such as \cite{SchCameraCalib} and \cite{hamrouni2012new}) try to consider the distortion due to the lens tilt caused by, in turn, the use of the Scheimpflug principle. \\

In literature there is a multitude of calibration algorithms, most developed for stereocamera systems. In this subsection we briefly introduced two algorithms that can be used to calibrate laser triangulation systems, proposed by Tsai \cite{TsaiTvLenses} (the pioneer of camera calibration algorithms) and Zhang \cite{Zhang-calib}. Both the algorithms are based on the pinhole projective model, described in Equation \ref{eq:perspective_projection}, and take in input a grid of points, both in image and world reference systems, and give in output the camera parameters. As we can understand, the origin of the world reference system could be arbitrary, but the system must be consistent with the world.

The choice of to use these algorithms was done by their interest in our filed of study and by the availability of data to compare. However, the use of non-linear optimizations made it difficult to estimate some parameters of interest for the next analysis.

\subsubsection{Tsai}
Roger Tsai proposed its algorithm in 1987 in order to improve the already existing algorithms, that lacked of many informations, such as lens distortions. Thus, he introduced a two-step process: in the first step he evaluated the intrinsic parameters starting from the grid took in input; in the second step he applied a non-linear optimization to correctly evaluate intrinsic parameters, with particular attention with focal length and lens distortions. As shown in his article, he developed a very accurate, fast and versatile algorithm to calibrate cameras. Furthermore, one of the advantages of this technique is the ability to calibrate using a single planar view of the reference target. \\

As we can read in the Reg Wilson's FAQ\footnote{\url{http://www.ius.cs.cmu.edu/IUS/usrp2/rgw/www/faq.txt}, no longer available now.} we have to be cautious when we set Tsai parameters. First of all, it assumes that some nominal values, such as pixel sizes, sensor size and frame grabber are correct. In this way he simplifies some passages of the algorithm. Second we have to pay attention on the choice of the world reference system: if we consider the coplanar procedure, the origin of our coordinate reference system must to be far from the center of the sensor, otherwise the algorithm could be not work. \\
Both in coplanar and non-coplanar procedure, the input grid must have at least $11$ point to calibrate correctly. Furthermore, the points have to be taken broadly across the \acs{FOV} to let the non-linear optimization work properly. \\

Note that, in order to separate the effects of $f$ and $T_z$ on the image, there needs to be perspective distortion effects in the calibration data. For useable perspective distortion, the distance between the calibration points nearest and farthest from the camera should be on the same scale as the distance between the calibration points and the camera. This applies both to coplanar and non-coplanar calibration:

For co-planar calibration the worst situation is to have the 3D points lied in a plane parallel to the camera's image plane (all points at   equal distance away). Simple geometry tells us we can't separate the effects of $f$ and $T_z$. A relative angle of $30$ degrees or more is recommended to give some effective depth to the data points.

For non-coplanar calibration the worst case is to have the 3D points lied in a volume of space that is relatively small compared to the volume's distance to the camera. From a distance the image formation process is closer to orthographic (not perspective) projection and the calibration problem becomes poorly conditioned.

\subsubsection{Zhang}
Zhang developed an hybrid process that combines self-calibration (a grid similar to that of Tsai) and traditional calibration techniques (match between the same point in different images), which enables the linear estimation of all intrinsic parameters. To do that at least three images of a well known planar pattern (or reasonably considered such) are needed, taken in different positions. The motion of the pattern should not necessarily be known. The steps needed to calibrate the system are the following, to:
  \begin{enumerate}
    \item Print a pattern and attach it to a planar surface.
    \item Take a few images of the model plane under different orientations by moving either the plane or the camera. In the scenarios we are interested in, we will move the pattern keeping fixed the camera.
    \item Detect the feature points in the images.
    \item Estimate the five intrinsic parameters and all the extrinsic parameters using the closed-form solution.
    \item Refine all parameters, including lens distortion parameters.
  \end{enumerate}
Unlike Tsai, Zhang tries to estimate the lens distortions until the fourth degree. As the author admitted in the original paper, his algorithm could degenerate if the pattern took in the different frames, lies in parallel planes.

\bigskip
Now we can understand the importance of planar calibration algorithm in laser-based triangulation systems: the laser forms a flat plane in the 3D world reference system. All points we will acquire lie on this plane. From this point of view, Tsai is preferable with respect to Zhang, because it used a single view of scene, taken on the laser plane. Note that if we use a known pattern (i.e. a checkboard), we must be sure that the pattern lies on the laser plane, otherwise the map that obtained will be incorrect.


\section{Properties of point estimators}


\input{../header_function}

%---------- start document ---------- %
 \section{squarefree -- Squarefreeness tests}\linkedzero{squarefree}

There are two method groups.
A function in one group raises \linkingone{squarefree}{Undetermined} when it cannot determine squarefreeness.
A function in another group returns {\tt None} in such cases.
The latter group of functions have ``\_ternary'' suffix on their names.
We refer a set \(\{{\tt True}, {\tt False}, {\tt None}\}\) as {\it ternary}\linkedone{squarefree}{ternary}.

The parameter type {\it integer}\linkedone{squarefree}{integer} means either {\it int}, {\it long} or \linkingone{rational}{Integer}.

This module provides an exception class.
\begin{description}
  \item[Undetermined]:\ Report undetermined state of calculation.
    The exception will be raised by
    \linkingone{squarefree}{lenstra} or
    \linkingone{squarefree}{trivial\_test}.
\end{description}

\subsection{Definition}

  We define squarefreeness as:\\
  \(n\) is squarefree \(\iff\) there is no prime \(p\) whose square divides \(n\).

\vspace{1em}
\noindent Examples:
  \begin{itemize}
  \item \(0\) is non-squarefree because any square of prime can divide \(0\).
  \item \(1\) is squarefree because there is no prime dividing \(1\).
  \item \(2\), \(3\), \(5\), and any other primes are squarefree.
  \item \(4\), \(8\), \(9\), \(12\), \(16\) are non-squarefree composites.
  \item \(6\), \(10\), \(14\), \(15\), \(21\) are squarefree composites.
\end{itemize}

 \subsection{lenstra -- Lenstra's condition}\linkedone{squarefree}{lenstra}
 \func{lenstra}{\hiki{n}{integer}}{\out{bool}}\\
 \spacing
 % document of basic document
 \quad If return value is True, \param{n} is squarefree.  Otherwise, the
 squarefreeness is still unknown and \linkingone{squarefree}{Undetermined} is raised.
 The algorithm is based on~\cite{Lenstra1979}. \\
 \spacing
 % added document
 \negok The condition is so strong that it seems \param{n} has to be a
 prime or a Carmichael number to satisfy it.\\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an odd \linkingone{squarefree}{integer}.
 %
 \subsection{trial\_division -- trial division}\linkedone{squarefree}{trial\_division}
 \func{trial\_division}{\hiki{n}{integer}}{\out{bool}}\\
 \spacing
 % document of basic document
 \quad Check whether \param{n} is squarefree or not. \\
 \spacing
 % added document
 The method is a kind of trial division and inefficient for large numbers. \\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an \linkingone{squarefree}{integer}.
%
 \subsection{trivial\_test -- trivial tests}\linkedone{squarefree}{trivial\_test}
 \func{trivial\_test}{\hiki{n}{integer}}{\out{bool}}\\
 \spacing
 % document of basic document
 \quad Check whether \param{n} is squarefree or not.  If the squarefreeness is still unknown, then \linkingone{squarefree}{Undetermined} is raised. \\
 \spacing
 % added document
 This method do anything but factorization including Lenstra's method. \\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an odd \linkingone{squarefree}{integer}.
%
 \subsection{viafactor -- via factorization}\linkedone{squarefree}{viafactor}
 \func{viafactor}{\hiki{n}{integer}}{\out{bool}}\\
 \spacing
 % document of basic document
 \quad Check whether \param{n} is squarefree or not. \\
 \spacing
 % added document
 It is obvious that if one knows the prime factorization of the number, he/she can tell whether the number is squarefree or not. \\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an \linkingone{squarefree}{integer}.
%
 \subsection{viadecomposition -- via partial factorization}\linkedone{squarefree}{viadecomposition}
 \func{viadecomposition}{\hiki{n}{integer}}{\out{bool}}\\
 \spacing
 % document of basic document
 \quad Test the squarefreeness of \param{n}.
 The return value is either one of {\tt True} or {\tt False};
 {\tt None} never be returned. \\
 \spacing
 % added document
 The method uses partial factorization into squarefree parts,
 if such partial factorization is possible.  In other cases,
 It completely factor \param{n} by trial division.
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an \linkingone{squarefree}{integer}.
%
 \subsection{lenstra\_ternary -- Lenstra's condition, ternary version}\linkedone{squarefree}{lenstra\_ternary}
 \func{lenstra\_ternary}{\hiki{n}{integer}}{\out{ternary}}\\
 \spacing
 % document of basic document
 \quad Test the squarefreeness of \param{n}. The return value is one of the ternary logical constants.  If return value is {\tt True}, \param{n} is squarefree.  Otherwise, the squarefreeness is still unknown and {\tt None} is returned. \\
 \spacing
 % added document
 \negok The condition is so strong that it seems \param{n} has to be a
 prime or a Carmichael number to satisfy it.\\
 This is a ternary version of \linkingone{squarefree}{lenstra}. \\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an odd \linkingone{squarefree}{integer}.
 %
 \subsection{trivial\_test\_ternary -- trivial tests, ternary version}\linkedone{squarefree}{trivial\_test\_ternary}
 \func{trivial\_test\_ternary}{\hiki{n}{integer}}{\out{ternary}}\\
 \spacing
 % document of basic document
 \quad Test the squarefreeness of \param{n}.
 The return value is one of the ternary logical constants. \\
 \spacing
 % added document
 The method uses a series of trivial tests including \linkingone{squarefree}{lenstra\_ternary}. \\
 This is a ternary version of \linkingone{squarefree}{trivial\_test}. \\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an \linkingone{squarefree}{integer}.
%
 \subsection{trial\_division\_ternary  -- trial division, ternary version}\linkedone{squarefree}{trial\_division\_ternary}
 \func{trial\_division\_ternary}{\hiki{n}{integer}}{\out{ternary}}\\
 \spacing
 % document of basic document
 \quad Test the squarefreeness of \param{n}.
 The return value is either one of {\tt True} or {\tt False};
 {\tt None} never be returned. \\
 \spacing
 % added document
 The method is a kind of trial division. \\
 This is a ternary version of \linkingone{squarefree}{trial\_division}.\\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an \linkingone{squarefree}{integer}.
%
 \subsection{viafactor\_ternary -- via factorization, ternary version}\linkedone{squarefree}{viafactor\_ternary}
 \func{viafactor\_ternary}{\hiki{n}{integer}}{\out{ternary}}\\
 \spacing
 % document of basic document
 \quad Just for symmetry, this function is defined as an alias of \linkingone{squarefree}{viafactor}. \\
 \spacing
 % added document
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an \linkingone{squarefree}{integer}.
%
\C

%---------- end document ---------- %

\input{../footer}


\chapter{Assignment solutions-Hamilltonian Equation of Motion}
\begin{abox}
Assignment solution-1
\end{abox}
\begin{enumerate}
	\item $\left. \right. $
	\begin{answer}
		\begin{align*}
		\text{(A) }T&=\frac{1}{2} m\left(\dot{r}^{2}+r^{2} \dot{\theta}^{2}+\dot{z}^{2}\right)=\frac{m}{2}\left(\dot{r}^{2}+r^{2} \dot{\theta}^{2}+a^{2} r^{2} \dot{r}^{2}\right) \quad \because z=\frac{1}{2} a r^{2} \Rightarrow \quad \dot{z}=a r \dot{r}\\
		V&=m g z=\frac{1}{2} m g a r^{2} \\
		L&=\frac{m}{2}\left[\dot{r}^{2}\left(1+a^{2} r^{2}\right)+r^{2} \dot{\theta}^{2}-a g r^{2}\right]
	\intertext{	(a) $\theta$ is cyclic coordinate}
	\because \frac{\partial L}{\partial \theta}&=0, \Rightarrow \dot{p}_{\theta}=0 \Rightarrow P_{\theta}=\text{ constant}
	\intertext{(b) Hamiltonian}
	H&=\frac{p_{r}^{2}}{2 m\left(1+a^{2} r^{2}\right)}+\frac{p_{\theta}^{2}}{2 m r^{2}}+\frac{1}{2} m a g r^{2} \quad \\&\because \frac{\partial L}{\partial \dot{r}}=p_{r}=m\left(1+a^{2} r^{2}\right) \dot{r}\text{ and }\frac{\partial L}{\partial \dot{\theta}}=p_{\theta}=m r^{2} \dot{\theta}
		\end{align*}
	\end{answer}
	\item $\left. \right. $
	\begin{figure}[H]
		\centering
		\includegraphics[height=2cm,width=3.5cm]{diagram-20220314-9-crop}
	\end{figure}
    \begin{answer}
    	\begin{align*}
    	\because z&=a\left(x^{2}+y^{2}\right)
    	\intertext{Using equation of constrain, we must solve the given system in cylindrical co-ordinate.}
    	z&=a r^{2}, \dot{z}=2 a r \dot{r}\\
    	L&=\frac{1}{2} m\left(\dot{r}^{2}+r^{2} \dot{\theta}^{2}+\dot{z}^{2}\right)-m g z\\
    	\Rightarrow L=\frac{1}{2} m\left(\dot{r}^{2}+r^{2} \dot{\theta}^{2}+4 a^{2} r^{2} \dot{r}^{2}\right)-m g a r^{2}&=\frac{1}{2} m\left(\dot{r}^{2}\left(1+4 a^{2} r^{2}\right)+r^{2} \dot{\theta}^{2}\right)-m g a r^{2}\\
    	\text{Equation of motion }&\frac{d}{d t}\left(\frac{\partial L}{\partial \dot{r}}\right)-\frac{\partial L}{\partial r}=0\\
    	m \ddot{r}\left(1+4 a^{2} r^{2}\right)&+4 m \dot{r}^{2} a^{2} r-m r \dot{\theta}^{2}+2 m g a r=0\\
    	\text{At }z=z_{0}, \quad \dot{r}&=0, \quad r=r_{0} \Rightarrow+m r_{0} \dot{\theta}^{2}=2 m g a r_{0} \Rightarrow \dot{\theta}=\sqrt{2 g a}\\
    	\Rightarrow \frac{v}{r_{0}}=\sqrt{2 g a} \Rightarrow v&=\sqrt{2 g a} \cdot r_{0}=\sqrt{2 g a} \cdot\left(\frac{z_{0}}{a}\right)^{1 / 2} \Rightarrow v=\sqrt{2 g z_{0}}\\
    	\because z_{0}&=a r_{0}^{2}
    	\end{align*}
    \end{answer}
	\item $\left. \right. $
	\begin{answer}
		\begin{align*}
		(a) x_{1}=0, x_{2}=l \sin \theta \Rightarrow \dot{x}_{2}&=l \cos \theta \dot{\theta}\\
		y_{2}=y_{1}+l \cos \theta, \quad \dot{y}_{2}&=\dot{y}_{1}-l \sin \theta \dot{\theta}\\
		L=\frac{M}{2}\left(\dot{y}_{1}^{2}\right)+\frac{m}{2}\left(l^{2} \dot{\theta}^{2}+\dot{y}_{1}^{2}-2 l \dot{y}_{1} \dot{\theta} \sin \theta\right)&-\frac{k}{2} y_{1}^{2}+M g y_{1}+m g l \cos \theta+m g y_{1}\\
		\text{(b) Equation of motion: }\frac{d}{d t}\left(\frac{\partial L}{\partial \dot{y}_{1}}\right)&-\frac{\partial L}{\partial y_{1}}=0\\
		\frac{d}{d t}\left(M \dot{y}_{1}+m \dot{y}_{1}-m l \dot{\theta} \sin \theta\right)&-\left(-k y_{1}+M g+m g\right)=0 \\
		M \ddot{y}_{1}+m \ddot{y}_{1}-m l\left(\ddot{\theta} \sin \theta+\dot{\theta}^{2} \cos \theta\right)&-\left(-k y_{1}+M g+m g\right)=0\\
		M y_{1}+m y_{1}-m l\left(\theta \sin \theta+\theta^{2} \cos \theta\right)&-\left(-k y_{1}+M g+m g\right)=0\\
		\because \frac{d}{d t}\left(\frac{\partial L}{\partial \dot{\theta}}\right)-\left(\frac{\partial L}{\partial \theta}\right)&=0 \\
		\frac{d}{d t}\left(m l^{2} \dot{\theta}-m l \dot{y}_{1} \sin \theta\right)-\left(-m l \dot{y}_{1} \dot{\theta} \cos \theta\right)&-(m g l(-\sin \theta))=0
		\intertext{$\left(m l^{2} \ddot{\theta}-m l \ddot{y}_{1} \sin \theta-m l \dot{y}_{1} \cos \theta \dot{\theta}\right)+m l \dot{y}_{1} \dot{\theta} \cos \theta+m g l \sin \theta=0$
		$m l^{2} \ddot{\theta}-m l \ddot{y}_{1} \sin \theta+m g l \sin \theta=0$}
		\end{align*}
	\end{answer}
	\item $\left. \right. $
	\begin{answer}
		\begin{align*}
		L&=\frac{1}{2} m\left(\dot{x}^{2}+\dot{y}^{2}+\dot{z}^{2}\right)-[m g(-z)]\\
		L&=\frac{1}{2} m\left(a^{2} \dot{\theta}^{2}+a^{2} \sin ^{2} \theta \dot{\phi}^{2}\right)+m g a \cos (\pi-\theta)\\
		L&=\frac{1}{2} m\left(a^{2} \dot{\theta}^{2}+a^{2} \sin ^{2} \theta \dot{\phi}^{2}\right)-m g a \cos (\theta)\\
		H&=\sum \dot{q}_{1} p_{1}-L\\
		H&=\frac{p_{\theta}^{2}}{2 m a^{2}}+\frac{p_{\phi}^{2}}{2 m a^{2} \sin ^{2} \theta}+m a g \cos \theta \because \frac{\partial L}{\partial \dot{\theta}}=p_{\theta}=m a^{2} \dot{\theta}\text{ and } \frac{\partial L}{\partial \dot{\phi}}=p_{\phi}=m a^{2} \sin ^{2} \theta \dot{\phi}
		\end{align*}
	\end{answer}
	\item $\left. \right. $
	\begin{answer}
		\begin{align*}
		y&=a x^{2}\\
		\text{(a) }\dot{y}&=2 a x \dot{x}\\
		L&=\frac{m}{2}\left(\dot{x}^{2}+\dot{y}^{2}\right)-m g y=\frac{m}{2}\left(\dot{x}^{2}+4 a^{2} x^{2} \dot{x}^{2}\right)-m g a x^{2}\\
		L&=\frac{m}{2}\left(1+4 a^{2} x^{2}\right) \dot{x}^{2}-m g a x^{2}\\
	\text{	(b) }&\frac{d}{d t}\left(\frac{\partial L}{\partial \dot{x}}\right)-\frac{\partial L}{\partial x}=0\\
	\frac{d}{d t}&\left[m\left(1+4 a^{2} x^{2}\right) \dot{x}\right]-\left[4 m a^{2} \dot{x}^{2} x-2 \mathrm{~m} g\right.\text{ a }\left.x\right]=0\\
	m \ddot{x}&+4 m a^{2} \ddot{x} x^{2}+8 m a^{2} \dot{x} x \dot{x}-4 m a^{2} \dot{x}^{2} x+2 m g a x=0\\
	m \ddot{x}&+4 m a^{2} x^{2} \ddot{x}+4 m a^{2} x \dot{x}^{2}+2 m g a x=0\\
	\text{(c) }H&=\sum \dot{x} p_{x}-L\\
	H&=\frac{p_{x}^{2}}{2 m\left(1+4 a^{2} x^{2}\right)}+m g a x^{2} \quad \because \frac{\partial L}{\partial \dot{x}}=p_{x}=m\left(1+4 a^{2} x^{2}\right) \dot{x}
		\end{align*}
	\end{answer}
	\item $\left. \right. $
	\begin{answer}
		\begin{align*}
		L&=e^{\alpha t}\left(\frac{m \dot{x}^{2}}{2}-\frac{k x^{2}}{2}\right)\\
		\text{(a) }\frac{d}{d t}\left(e^{\alpha t} m \dot{x}\right)-e^{\alpha t} k x&=0 \Rightarrow e^{\alpha t} m \ddot{x}+m \dot{x} e^{\alpha t} \cdot \alpha-e^{\alpha t} k x=0 \Rightarrow e^{\alpha t}[m \ddot{x}+\alpha m \dot{x}-k x]=0\\
		\text{(b) }H&=e^{-\alpha t} \frac{p_{x}^{2}}{2 m}+e^{\alpha t} \frac{k x^{2}}{2}
		\because \frac{\partial L}{\partial \dot{x}}=p_{x}=e^{\alpha t} m \dot{x}
		\end{align*}
	\end{answer}
	\item $\left. \right. $
	\begin{answer}
		\begin{align*}
		L&=\frac{m_{1} \dot{x}_{1}^{2}}{2}+\frac{m_{2}\left(\dot{x}_{2}^{2}+\dot{y}_{2}^{2}\right)}{2}-\left(-m_{2} g y_{2}\right)\\
		x_{2}&=x_{1}+l \sin \phi, y_{2}=l \cos \phi\\
		\Rightarrow \dot{x}_{2}&=\dot{x}_{1}+l \cos \phi \dot{\phi}, \quad \dot{y}_{2}=-l \sin \phi \dot{\phi}\\
		\text{(a) }L&=\frac{1}{2}\left(m_{1}+m_{2}\right) \dot{x}_{1}^{2}+\frac{1}{2} m_{2}\left(l^{2} \dot{\phi}^{2}+2 l \dot{x}_{1} \dot{\phi} \cos \phi\right)+m_{2} g l \cos \phi\\
		\text{(b) }x_{1}&\text{ is cyclic coordinate}\\
		\because \frac{\partial L}{\partial x_{1}}&=0 \Rightarrow p_{x}=\left(m_{1}+m_{2}\right) \dot{x}_{1}+m_{2} l \dot{\phi} \cos \phi\\
		\text{(c) }\frac{\partial L}{\partial \dot{\phi}}&=p_{\phi}=m_{2} l^{2} \dot{\phi}+l \dot{x}_{1} \cos \phi, \quad p_{x}=\left(m_{1}+m_{2}\right) \dot{x}_{1}+m_{2} l \dot{\phi} \cos \phi
		\end{align*}
	\end{answer}
	\item $\left. \right. $
	 \begin{figure}[H]
		\centering
		\includegraphics[height=5.5cm,width=5.5cm]{Assignment-HE-05}
	\end{figure}
	\begin{answer}
		\begin{align*}
		\intertext{(a) We choose the origin of our coordinate system to be at the center of the rotating rim. The Cartesian components of mass $m$ become}
		&\left.\begin{array}{l}x=a \cos \omega t+b \sin \theta \\ y=b \cos \theta-a \sin \omega t\end{array}\right\}
		\intertext{The velocities are}
		&\left.\begin{array}{l}\dot{x}=-a w \sin \omega t+b \dot{\theta} \cos \theta \\ \dot{y}=-a \omega \cos \omega t-b \dot{\theta} \sin \theta\end{array}\right\}
		\intertext{Taking the time derivative once again gives the acceleration:}
		\ddot{x}&=-a \omega^{2} \cos \omega t+b\left(\ddot{\theta} \cos \theta-\dot{\theta}^{2} \sin \theta\right)\\
		\ddot{y}&=+a \omega^{2} \sin \omega t-b\left(\ddot{\theta} \sin \theta+\dot{\theta}^{2} \cos \theta\right)
		\intertext{(b) It should now be clear that the single generalized coordinate is $\theta$. The kinetic and potential energies are}
	T &=\frac{1}{2} m\left(\dot{x}^{2}+\dot{y}^{2}\right) \\
	 U &=-m g y \\
	 \text{where }U&=0\text{ at }y=0.
	 \intertext{The Lagrangian of a system is given by}
	 L&=T-U=\frac{m}{2}\left[a^{2} \omega^{2}+b^{2} \dot{\theta}^{2}+2 b \dot{\theta} a \omega \sin (\theta-\omega t)\right]+m g(b \cos \theta-a \sin \omega t)
	 \intertext{(c) The derivatives for the Lagrange equation of motion for $\theta$ are}
	 \frac{d}{d t} \frac{\partial L}{\partial \dot{\theta}}&=m b^{2} \ddot{\theta}+m b a \omega(\dot{\theta}-\omega) \cos (\theta-\omega t)\\
	 \frac{\partial L}{\partial \theta}&=m b \dot{\theta} a \omega \cos (\theta-\omega t)-m g b \sin \theta
	 \intertext{which results in the equation of motion (after solving for $\ddot{\theta}$ )}
	 \ddot{\theta}&=\frac{\omega^{2} a}{b} \cos (\theta-\omega t)-\frac{g}{b} \sin \theta
		\end{align*}
	\end{answer}
	\item $\left. \right. $
	  \begin{figure}[H]
		\centering
		\includegraphics[height=6cm,width=3.6cm]{Assignment-HE-06}
	\end{figure}
	\begin{answer}
		\begin{align*}
		\text{(a) }&r_{1}=a, r_{2}=a, \theta_{1}=\theta_{2}=\theta, \quad \phi_{3}=0, \quad \theta_{3}=0, \quad r_{3}=2 a \cos \theta, \quad \phi_{1}=\phi_{2}+c\\
		&\text{Degree of freedom }=3 \times 3-7=2\\
	\text{	(b) }&L=m_{1} a^{2}\left(\dot{\theta}^{2}+\omega^{2} \sin ^{2} \theta\right)+2 m_{2} a^{2} \dot{\theta}^{2} \sin ^{2} \theta+2\left(m_{1}+m_{2}\right) g a \cos \theta\\
		\text{(c) }&\frac{d}{d t}\left(\frac{\partial L}{\partial \dot{\theta}}\right)-\frac{\partial L}{\partial \theta}=0\\
		&\frac{d}{d t}\left(2 m_{1} a^{2} \dot{\theta}+4 m_{2} a^{2} \dot{\theta} \sin ^{2} \theta\right)-m_{1} a^{2} \omega^{2} 2 \sin \theta \cos \theta-2 m_{2} a^{2} \dot{\theta}^{2} 2 \sin \theta \cos \theta+2\left(m_{1}+m_{2}\right) g a \sin \theta=0\\
		&\Rightarrow\left(2 m_{1} a^{2}+4 m_{2} a^{2} \sin ^{2} \theta\right) \ddot{\theta}+2 m_{2} a^{2} \sin 2 \theta \dot{\theta}^{2}-m_{1} a^{2} \omega^{2} \sin 2 \theta+2\left(m_{1}+m_{2}\right) g a \sin \theta=0\\
	\text{	(d) }&H=\sum \dot{\theta} p_{\theta}-L\\
	&\frac{\partial L}{\partial \dot{\theta}}=p_{\theta}=2 m_{1} a^{2} \dot{\theta}+4 m_{2} a^{2} \dot{\theta} \sin ^{2} \theta \Rightarrow \dot{\theta}=\frac{p_{\theta}}{2 m_{1} a^{2}+4 m_{2} a^{2} \sin ^{2} \theta}\\
	H&=\frac{p_{\theta}^{2}}{4 m a^{2}+\theta m_{2} a^{2} \sin ^{2} \theta}-m_{1} a^{2} \omega^{2} \sin ^{2} \theta-2\left(m_{1}+m_{2}\right) g a \cos \theta
		\end{align*}
	\end{answer}
	\item $\left. \right. $
	 \begin{figure}[H]
		\centering
		\includegraphics[height=4.5cm,width=6.5cm]{Assignment-HE-07}
	\end{figure}
	\begin{answer}
		\begin{align*}
		L&=\frac{1}{2} m\left(\dot{r}^{2}+r^{2} \dot{\theta}^{2}+r^{2} \sin ^{2} \theta \dot{\phi}^{2}\right)-m g r \cos \theta\\
		\text{equation of constrain is }\theta&=\frac{\pi}{4}\text{ and it is given }\dot{\phi}=\omega\\
		L&=\frac{1}{2} m\left(\dot{r}^{2}+\frac{1}{2} r^{2} \omega^{2}\right)-\frac{1}{\sqrt{2}} m g r\\
	\text{	the momentum conjugate to $r$ is }p_{r}&=\frac{\partial L}{\partial \dot{r}} \quad \Rightarrow p_{r}=m \dot{r}
		\end{align*}
	\end{answer}
		\item $\left. \right. $
		  \begin{figure}[H]
			\centering
			\includegraphics[height=6cm,width=5.2cm]{Assignment-HE-08}
		\end{figure}
	\begin{answer}
		\begin{align}
		\intertext{Because the problem has cylindrical symmetry, we choose $r, \theta$ and $z$ as the generalized coordinates. The kinetic energy of the bead is}
		T&=\frac{m}{2}\left[\dot{r}^{2}+\dot{z}^{2}+(r \dot{\theta})^{2}\right]\notag\\
	\text{	If we choose }U=0\text{ at }z&=0\text{, the potential energy term is}\notag\\
	U&=m g z\notag
	\intertext{But $r, z$ and $\theta$ are not independent. The equation of constraint for the parabola is}
	z&=c r^{2} \Rightarrow \dot{z}=2 c \dot{r} r\notag
	\intertext{We also have an explicit time dependence of the angular rotation}\notag
	\theta&=\omega t \Rightarrow \dot{\theta}=\omega\notag
	\intertext{We can now construct the Lagrangian as being dependent only on $r$, because there is no direct $\theta$ dependence.}
	L&=T-U=\frac{m}{2}\left(\dot{r}^{2}+4 c^{2} r^{2} \dot{r}^{2}+r^{2} \omega^{2}\right)-m g c r^{2}\notag
	\intertext{The problem stated that the bead moved in a circle of radius $R$. The reader might be tempted at this point to let $r=R=$ constant and $\dot{r}=0$. It would be a mistake to do this now in the Lagrangian. First, we should find the equation of motion for the variable $r$ and then let $r=R$ as a condition of the particular motion. This determines the particular value of $c$ needed for $r=R$.}\notag
	\frac{\partial L}{\partial \dot{r}}&=\frac{m}{2}\left(2 \dot{r}+8 c^{2} r^{2} \dot{r}\right), \frac{d}{d t} \frac{\partial L}{\partial \dot{r}}=\frac{m}{2}\left(2 \ddot{r}+16 c^{2} r \dot{r}^{2}+8 c^{2} r^{2} \ddot{r}\right)\notag\\
	\frac{\partial L}{\partial \dot{r}}&=m\left(4 c^{2} r \dot{r}^{2}+r \omega^{2}-2 g c r\right)\notag
	\intertext{Lagrange's equation of motion becomes}\notag\\
	\ddot{r}\left(1+4 c^{2} r^{2}\right)&+\dot{r}^{2}\left(4 c^{2} r\right)+r\left(2 g c-\omega^{2}\right)=0\label{HE-01}
	\intertext{which is a complicated result. If, however, the bead rotates with $r=R=$ constant, then $\dot{r}=\ddot{r}=0$ and equation (\ref{HE-01}) becomes}
	R\left(2 g c-\omega^{2}\right)&=0 \Rightarrow \omega=\sqrt{2 g c}\notag
		\end{align}
	\end{answer}
\end{enumerate}
\begin{abox}
	Assignment solution-2
\end{abox}
\begin{enumerate}
	\item $\left. \right. $
\begin{answer}
	\begin{align*}
	\text{Poisson bracket }\left[p_{x}-3 y, H\right]&=0 and \left[p_{y}+2 y, H\right]=0\\
	p_{y}(b-3)+x\left(3 b-b^{2}\right)&=0\text{ and }p_{x}(a+2)-y\left(2 a+a^{2}\right)=0\\
	\Rightarrow a&=-2, b=3
	\end{align*}
\end{answer}
	\item $\left. \right. $
	\begin{answer}
		\begin{align*}
		H&=\sum \dot{q} p-L\text{ where }L=\frac{1}{2} m \dot{q}^{2}-\frac{1}{2} \lambda q \dot{q}^{2}\\
		\frac{\partial L}{\partial \dot{q}}&=p=m \dot{q}-\lambda q \dot{q} \Rightarrow p=\dot{q}(m-\lambda q) \Rightarrow \dot{q}=\frac{p}{m-\lambda q}\\
		\Rightarrow H&=\dot{q} p-L=\frac{p^{2}}{(m-\lambda q)}-\frac{1}{2} m \frac{\left(p^{2}\right)}{(m-\lambda q)^{2}}+\frac{\lambda}{2} q \cdot \frac{p^{2}}{(m-\lambda q)^{2}}\\
		\Rightarrow H&=\frac{p^{2}}{(m-\lambda q)}-\frac{p^{2}}{2(m-\lambda q)^{2}}(m-\lambda q)=\frac{p^{2}}{(m-\lambda q)}-\frac{p^{2}}{2(m-\lambda q)}\\
		\Rightarrow H&=\frac{p^{2}}{2(m-\lambda q)}
		\end{align*}
	\end{answer}
	\item $\left. \right. $
	\begin{answer}
		\begin{align*}
	\text{	(a) }\left\{C_{1}, C_{2}\right\}&=\left\{x_{2} p_{3}+x_{3} p_{2}, x_{1} p_{2}-x_{2} p_{1}\right\}\\
		\left\{C_{1}, C_{2}\right\} &=\left\{x_{2} p_{3}, x_{1} p_{2}\right\}-\left\{x_{2} p_{3}, x_{2} p_{1}\right\}+\left\{x_{3} p_{2}, x_{1} p_{2}\right\}-\left\{x_{3} p_{2}, x_{2} p_{1}\right\} \\
		&=x_{1}\left\{x_{2}, p_{2}\right\} p_{3}+0+0-x_{3}\left\{p_{2}, x_{2}\right\} p_{1}\\
		\Rightarrow\left\{C_{1}, C_{2}\right\}&=x_{1} p_{3}+x_{3} p_{1}\\
		\text{(b) }\left\{C_{1}, C_{2}\right\}&=C_{3}
		\end{align*}
	\end{answer}
	\item $\left. \right. $
\begin{answer}
	\begin{align*}
	\text{If $u$ is conserve then }\frac{d u}{d t}&=[u, H]+\frac{\partial u}{\partial t}=0 \Rightarrow \frac{d u}{d t}=\frac{\partial u}{\partial x} \cdot \frac{\partial H}{\partial p}-\frac{\partial u}{\partial p} \cdot \frac{\partial H}{\partial x}+\frac{\partial u}{\partial t}\\
	\Rightarrow \frac{d u}{d t}&=\frac{i m \omega}{p+i m \omega x} \cdot \frac{p}{m}-\frac{1}{p+i m \omega x} \cdot m \omega^{2} x-i \omega\\
	&=\frac{i \omega p}{p+i m \omega x}-\frac{m \omega^{2} x}{p+i m \omega x}-i \omega=\frac{i \omega(p+i m \omega x)}{p+i m \omega x}-i \omega=0
	\intertext{So $u$ is conserve during the motion}
	\end{align*}
\end{answer}
	\item $\left. \right. $
\begin{answer}
	\begin{align*}
	\intertext{(a) Solving Hamiltonian equation of motion}
	\frac{\partial H}{\partial x}&=-\dot{p}_{x} \Rightarrow p_{x}-x=-\dot{p}_{x}\text{ and }\frac{\partial H}{\partial y}=-\dot{p}_{y} \Rightarrow-p_{y}+y=-\dot{p}_{y}\\
	\frac{\partial H}{\partial p_{x}}&=\dot{x} \Rightarrow x=\dot{x}\text{ and } \frac{\partial H}{\partial p_{y}}=\dot{y} \Rightarrow-y=\dot{y}
	\intertext{(b) After solving these four differential equation and eliminating time $t$ and using boundary condition one will get $\Rightarrow x \propto \frac{1}{y}$ and $p_{x} \propto \frac{1}{p_{y}}$}
	\end{align*}
\end{answer}
	\item $\left. \right. $
\begin{answer}
	\begin{align}
	H&=\frac{p^{2}}{2 m}+\frac{1}{2} m \omega^{2} q^{2}, \quad F=F_{1}(q, Q)=-\frac{Q}{q}\notag\\
	\Rightarrow \frac{\partial F_{1}}{\partial q}&=p \Rightarrow \frac{Q}{q^{2}}=p\label{HE02}\\
	\Rightarrow \frac{\partial F_{1}}{\partial Q}&=-P \Rightarrow-\frac{1}{q}=-P \Rightarrow q=\frac{1}{P}\label{HE-03}
	\intertext{From equation (\ref{HE02}) and (\ref{HE-03}) $\Rightarrow p=Q P^{2}$	$
		\quad \because q=\frac{1}{P}	$}\notag
	H&=\frac{p^{2}}{2 m}-\frac{1}{2} m \omega^{2} q^{2}=\frac{Q^{2} P^{4}}{2 m}-\frac{1}{2} m \omega^{2}\left(\frac{1}{P^{2}}\right)=\frac{1}{2 m} Q^{2} P^{4}-\frac{1}{2} m \omega^{2} P^{-2}\notag
	\end{align}
\end{answer}
	\item $\left. \right. $
\begin{answer}
	\begin{align*}
		H&=\frac{p_{x}^{2}}{2 m}+\frac{p_{y}^{2}}{2 m}+\frac{1}{2} m \omega^{2}\left(x^{2}+y^{2}\right) \quad S_{1}=\frac{1}{2}\left(x p_{y}-y p_{x}\right)\\
		\text{(a) }&\left[S_{1}, H\right]=0\\
		&\Rightarrow \frac{\partial S_{1}}{\partial x} \frac{\partial H}{\partial p_{x}}-\frac{\partial S_{1}}{\partial p_{x}} \frac{\partial H}{\partial x}+\frac{\partial S_{1}}{\partial y} \frac{\partial H}{\partial p_{y}}-\frac{\partial S_{1}}{\partial p_{y}} \cdot \frac{\partial H}{\partial y} \\
		&\Rightarrow \frac{p_{y}}{2} \cdot \frac{p_{x}}{m}-\left(-\frac{y}{2}\right) \cdot m \omega^{2} x+\frac{1}{2}\left(-p_{x}\right) \cdot \frac{p_{y}}{m}-\frac{1}{2}(x) \cdot m \omega^{2} y=0\\
		\text{(b) }&\left[S_{2}, H\right]=0\hspace{2cm}
		S_{2}=\frac{1}{2 m \omega}\left(p_{x} p_{y}+m^{2} \omega^{2} x y\right)\\
		&\Rightarrow \quad \frac{\partial S_{2}}{\partial x} \frac{\partial H}{\partial p_{x}}-\frac{\partial S_{2}}{\partial p_{x}} \frac{\partial H}{\partial x}+\frac{\partial S_{2}}{\partial y} \frac{\partial H}{\partial p_{y}}-\frac{\partial S_{2}}{\partial p_{y}} \frac{\partial H}{\partial y}\\
		&\Rightarrow \quad \frac{1}{2 m \omega}\left(m^{2} \omega^{2} y\right)\left(\frac{p_{x}}{m}\right)-\frac{p_{y}}{2 m \omega} \cdot\left(m \omega^{2} x\right)+\frac{1}{2 m \omega} m^{2} \omega^{2} x \cdot \frac{p_{y}}{m}-\frac{p_{x}}{2 m \omega} \cdot m \omega^{2} y=0\\
		\text{(c) }&\left[S_{3}, H\right]=0\\
		&\frac{\partial S_{3}}{\partial x} \frac{\partial H}{\partial p_{x}}-\frac{\partial S_{3}}{\partial p_{x}} \frac{\partial H}{\partial x}+\frac{\partial S_{3}}{\partial y} \frac{\partial H}{\partial p_{y}}-\frac{\partial S_{3}}{\partial p_{y}} \cdot \frac{\partial H}{\partial y} \\
		&\Rightarrow \frac{1}{4 m \omega} \times m^{2} \omega^{2}(-2 x) \cdot \frac{p_{x}}{m}-\frac{1}{4 m \omega} \times 2 p_{x} \cdot m \omega^{2} x+\frac{m^{2} \omega^{2}}{4 m \omega} \times 2 y \cdot \frac{p_{y}}{m}-\frac{1}{4 m \omega}\left(-2 p_{y} \cdot m \omega^{2} y\right) \\
		&\Rightarrow \frac{-p_{x} x \omega}{2}-\frac{p_{x} \omega x}{2}+\frac{p_{y} \cdot y \omega}{2}+\frac{p_{y} y \omega}{2} \neq 0
	\end{align*}
\end{answer}
	\item $\left. \right. $
\begin{answer}
	\begin{align*}
	Q&=\log \left(1+q^{\frac{1}{2}} \cos p\right)\\
	P&=2\left(1+q^{\frac{1}{2}} \cos p\right) q^{\frac{1}{2}} \sin p \Rightarrow 2 q^{\frac{1}{2}} \sin p+q \sin 2 p\\
\text{	(a) }&\text{For canonical transformation: }\frac{\partial Q}{\partial q} \cdot \frac{\partial P}{\partial p}-\frac{\partial Q}{\partial p} \cdot \frac{\partial P}{\partial q}=1\\
	&\Rightarrow \frac{\partial Q}{\partial q}=\frac{1}{\left(1+q^{\frac{1}{2}} \cos p\right)} \times \frac{1}{2} q^{-\frac{1}{2}} \cos p, \frac{\partial Q}{\partial p}=\frac{q^{\frac{1}{2}}(-\sin p)}{\left(1+q^{\frac{1}{2}} \cos p\right)}\\
	\frac{\partial P}{\partial p}&=2 q^{\frac{1}{2}} \cos p+2 q \cos 2 p, \frac{\partial P}{\partial q}=2 \times \frac{1}{2} q^{-\frac{1}{2}} \sin p+\sin 2 p\\
	&\Rightarrow \frac{\cos p}{2\left(1+q^{\frac{1}{2}} \cos p\right) q^{\frac{1}{2}}} \cdot 2\left(q^{\frac{1}{2}} \cos p+q \cos 2 p\right)-\frac{\left(-q^{\frac{1}{2}} \sin p\right)}{\left(1+q^{\frac{1}{2}} \cos p\right)} \times\left(q^{-\frac{1}{2}} \sin p+\sin 2 p\right)=1\\
	\text{(b) }F_{3}&=F_{3}(p, Q, t)\\
	\frac{\partial F_{3}}{\partial p}&=-q, \quad \frac{\partial F_{3}}{\partial Q}=-P \\
	Q&=\log \left(1+q^{1 / 2} \cos p\right) \Rightarrow e^{Q}=1+q^{1 / 2} \cos p\\
	\frac{e^{Q}-1}{\cos p}&=q^{1 / 2} \Rightarrow q=\left(\frac{e^{Q}-1}{\cos p}\right)^{2}\\
	P&=2\left(1+q^{1 / 2} \cos p\right) q^{1 / 2} \sin p \Rightarrow P=2 e^{Q} q^{1 / 2} \sin p \Rightarrow 2 e^{Q}\left(e^{Q}-1\right) \tan p\\
	\frac{\partial F_{3}}{\partial p}&=-q=-\frac{\left(e^{Q}-1\right)^{2}}{\cos ^{2} p} \Rightarrow F_{3}=-\int\left(e^{Q}-1\right)^{2} \sec ^{2} p d p
	\end{align*}
	\begin{align}
	F_{3}&=-\left(e^{Q}-1\right)^{2} \tan p+f_{1}(Q)\label{HE-04}\\
	\frac{\partial F_{3}}{\partial Q}&=-P=-2\left(e^{2 Q}-e^{Q}\right) \tan p\notag\\
	F_{3}&=-2\left(\frac{1}{2} e^{2 Q}-e^{Q}\right) \tan p+f_{2}(p)=-\left(e^{Q}-1\right)^{2} \tan p+\tan p+f_{2}(p) \label{HE-05}
\intertext{	Equating $\ref{HE-04}$ and $\ref{HE-05}$}
	f_{1}(Q)&=0, \quad f_{2}(p)=-\tan p\notag\\
	\text{So }F_{3}&=-\left(e^{Q}-1\right)^{2} \tan p \notag
	\end{align}
\end{answer}
	\item $\left. \right. $
\begin{answer}
	\begin{align*}
	\frac{\partial Q_{1}}{\partial q_{1}} \frac{\partial P_{1}}{\partial p_{1}}&-\frac{\partial Q_{1}}{\partial p_{1}} \frac{\partial P_{1}}{\partial q_{1}}+\frac{\partial Q_{1}}{\partial q_{2}} \frac{\partial P_{1}}{\partial p_{2}}-\frac{\partial Q_{1}}{\partial p_{2}} \frac{\partial P_{1}}{\partial q_{2}}=1 \times 1-0=1\\
	\text{and }&\frac{\partial Q_{1}}{\partial q_{1}} \frac{\partial P_{1}}{\partial p_{1}}-\frac{\partial Q_{1}}{\partial p_{1}} \frac{\partial P_{1}}{\partial q_{1}}+\frac{\partial Q_{2}}{\partial q_{2}} \frac{\partial P_{2}}{\partial p_{2}}-\frac{\partial Q}{\partial p_{2}} \frac{\partial P_{2}}{\partial q_{2}}=0-(-1)=1
	\end{align*}
\end{answer}
	\item $\left. \right. $
\begin{answer}$\left. \right. $
		\begin{figure}[H]
		\centering
		\includegraphics[height=2.5cm,width=5cm]{Assignment-HE-13.pdf}
	\end{figure}
	\begin{align*}
	\text{(A)\quad (a)\quad }H&=\frac{1}{2 m}\left[p^{2}+m^{2} \omega^{2} q^{2}\right]\\
	\frac{\partial H}{\partial p}&=\dot{q} \Rightarrow \frac{p}{m}=\dot{q} \Rightarrow p=m \dot{q}\\
	\frac{\partial H}{d q}&=-\dot{p} \Rightarrow m \omega^{2} q=-\dot{p}\\
	-m \omega^{2} q&=m \ddot{q}\\\
	\ddot{q}+\omega^{2} q&=0\\
	q&=A \cos \omega t+B \sin \omega t
	\end{align*}
		\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=4cm]{Assignment-HE-14.pdf}
	\end{figure}
	\begin{align*}
	\text{(b) \quad}&\frac{p^{2}}{(\sqrt{2 m E})^{2}}+\frac{q^{2}}{\left(\sqrt{\frac{2 E}{m \omega^{2}}}\right)^{2}}=1\\
	\text{(c) \quad}&\text{ With initial condition, when }t=0, q=q_{0}\text{ and } \dot{q}=0\text{ at }t=0\\
	\text{Then, }q_{0}&=A\text{ and }q=q_{0} \cos \omega t\\
	\text{(d) }\quad p&=m \dot{q}\\
	p&=-q_{0} \omega m \sin \omega t
	\end{align*}
		\begin{figure}[H]
		\centering
		\includegraphics[height=2.8cm,width=4.5cm]{Assignment-HE-12.pdf}
	\end{figure}
	\begin{align*}
\text{	(B)\quad  (a)\quad }F_{1}&=\frac{m \omega q^{2}}{2} \cot Q, \frac{\partial F_{1}}{\partial q}=p, \frac{\partial F_{1}}{\partial Q}=-P\\
m \omega q \cdot \cot Q&=p,-\frac{m \omega q^{2}}{2} \operatorname{cosec} Q=-P\\
q^{2}&=\frac{2 P}{m \omega} \frac{1}{\operatorname{cosec}{ }^{2} Q}\\
q&=\sqrt{\frac{2 P}{m \omega}} \sin Q, p=m \omega \sqrt{\frac{2 P}{m \omega}} \cot Q \sin Q\\
p&=\sqrt{2 m P \omega} \cos Q\\
\text{(b) }\quad H&=\frac{p^{2}}{2 m}+\frac{1}{2} m \omega^{2} q^{2}\\
K&=H+\frac{\partial F_{1}}{\partial t} \Rightarrow \frac{\partial F_{1}}{\partial t}=0, K=H=\frac{1}{2 m}(\sqrt{2 P m \omega} \cos Q)^{2}+\frac{1}{2} m \omega^{2}\left(\sqrt{\frac{2 P}{m \omega}}\right)^{2} \sin ^{2} Q\\
K&=\omega P\\
\text{(c)\quad}&
\frac{\partial K}{\partial Q}=-\dot{P} \Rightarrow \dot{P}=0, \frac{d P}{d t}=0, P=c\\
\frac{\partial K}{\partial P}&=\dot{Q}=\omega, Q=\omega t+\alpha\text{ where } \alpha\text{ is constant, can be find with initial condition}
	\end{align*}
	\begin{figure}[H]
		\centering
		\includegraphics[height=2.8cm,width=4.5cm]{Assignment-HE-09.pdf}
	\end{figure}
 \begin{tasks}(1)
	\task[\text{(d)}]
	\begin{figure}[H]
		\centering
		\includegraphics[height=2.8cm,width=4.5cm]{Assignment-HE-10.pdf}
	\end{figure}where $P=\frac{E}{\omega}$
	\task[\text{(e)}]
		\begin{figure}[H]
		\centering
		\includegraphics[height=2.8cm,width=4.5cm]{Assignment-HE-11.pdf}
	\end{figure}
\end{tasks}
\end{answer}
	\item $\left. \right. $
	\begin{answer}
		\begin{align*}
		F_{2}&=q^{2} P\\
		\frac{\partial F_{2}}{\partial q}&=2 q P=p, \frac{\partial F_{2}}{\partial P}=q^{2}=Q, q=\sqrt{Q}, p=2 \sqrt{Q} P\\
		K&=\frac{p^{2}}{2 \alpha q^{2}}+\frac{\beta \cdot q^{4}}{4}=\frac{4 Q P^{2}}{2 \alpha Q}+\frac{\beta Q^{2}}{4} \Rightarrow K=\frac{2 P^{2}}{\alpha}+\frac{\beta Q^{2}}{4}\\
		\frac{\partial K}{\partial P}&=\dot{Q} \Rightarrow \frac{4 P}{\alpha}=\dot{Q}\\
		\frac{\partial K}{\partial Q}&=-\dot{P} \Rightarrow \frac{\beta Q}{2}=-\dot{P}
		\end{align*}
	\end{answer}
	\item $\left. \right. $
	\begin{answer}
		\begin{align*}
		\text{(a) }L&=\frac{1}{2} m \dot{x}^{2}+m\left(\dot{y}^{2}+\dot{z}^{2}\right)-\frac{1}{2} k x^{2}-\frac{1}{2} k(y+z)^{2}\\
		H&=\frac{p_{x}^{2}}{2 m}+\frac{p_{y}^{2}}{4 m}+\frac{p_{z}^{2}}{4 m}+\frac{1}{2} k x^{2}+\frac{1}{2} k(y+z)^{2}\\
		\text{(b) }\quad L_{z}^=x p_{y}-y p_{x}\\
		\frac{d L_{z}}{d t}&=\left[L_{z} H\right]+\frac{\partial L_{z}}{\partial t}, \frac{\partial L_{z}}{\partial t}=0\\
		\left[L_{z}, H\right]&=\left[x p_{y}-y p_{x}, H\right]=x\left[p_{y}, H\right]+[x, H] p_{y}-y\left[p_{x}, H\right]-[y, H] p_{x} \\
		&=x\left[p_{y}, \frac{1}{2} k(y+z)^{2}\right]+\left[x, \frac{p_{x}^{2}}{2 m}\right] p_{y}-y\left[p_{x}, \frac{1}{2} k x^{2}\right]-\left[y, \frac{p_{y}^{2}}{4 m}\right] p_{x}\\
		&=x(-k(y+z))+\frac{p_{x} p_{y}}{m}+k y x-\frac{p_{x} p_{y}}{2 m}\\
		\left[L_{z}, H\right]&=\frac{p_{y} p_{x}}{2 m}-k x z, \frac{d L_{z}}{d t}=\frac{p_{x} p_{y}}{2 m}-k x z \\
		\text{(c) }\quad\left[L_{x}, H\right]&=\left[y p_{z}-z p_{y}, H\right]=\left[y p_{z}, H\right]-\left[z p_{y}, H\right]\\
		&=[y, H] p_{z}+y\left[p_{z}, H\right]-[z, H] p_{y}-z\left[p_{y}, H\right]\\
		&=\left[y, \frac{p_{y}^{2}}{4 m}\right] p_{z}+y\left[p_{z}, \frac{1}{2} k(y+z)^{2}\right]-\left[z, \frac{p_{z}^{2}}{4 m}\right] p_{y}-z\left[p_{y}, \frac{1}{2} k(y+z)^{2}\right]\\
		&=\frac{p_{y}}{2 m} p_{z}+y[-k(y+z)]-\frac{p_{z}}{2 m} p_{y}+k z(y+z)=-k y^{2}-k z y+k z y+k z^{2}\\
		\left[L_{x}, H\right]&=k\left[z^{2}-y^{2}\right], \frac{d L_{x}}{d t}=k\left[z^{2}-y^{2}\right] \\
		\text{(d) }\quad \frac{d L_{y}}{d t}&=-\frac{p_{x} p_{z}}{2 m}+k x y\\
	\text{	(e)\quad }
		\frac{\partial H}{\partial x}&=-\dot{p}_{x}, k x=-\dot{p}_{x}=\frac{-d p_{x}}{d t} \Rightarrow \frac{d p_{x}}{d t}=-k x\\
		\frac{\partial H}{\partial y}&=-\dot{p}_{y}, \frac{2 k}{2}(y+z)=-\dot{p}_{y}, \frac{d p_{y}}{d t}=-k(y+z)
		\end{align*}
	\end{answer}
\end{enumerate}

Classical Mechanics  -CSIR/chapter/Assignments/Assignment solutions-Hamilltonian Equation of Motion.tex


\chapter{Categories related with funcoids}

I consider some categories related with pointfree funcoids.

\section{Draft status}

This is a rough partial draft.

\section{Topic of this article}

In this article are considered some categories related to \emph{pointfree
funcoids}.

\section{Category of continuous morphisms}

I will denote $\Ob f$ the object (source and destination) of an
endomorphism $f$.

\begin{defn}
  Let $C$ is a partially ordered category. The category
  $\cont (C)$ (which I call \emph{the category of
  continuous morphism} over $C$) is:
  \begin{itemize}
    \item Objects are endomorphisms of category $C$.

    \item Morphisms are triples $(f , a , b)$ where $a$ and $b$ are objects
    and $f : \Ob a \rightarrow \Ob b$ is a morphism of the
    category $C$ such that $f \circ a \sqsubseteq b \circ f$.

    \item Composition of morphisms is defined by the formula $(g , b , c)
    \circ (f , a , b) = (g \circ f , a , c)$.

    \item Identity morphisms are $(a , a , 1^C_a)$.
  \end{itemize}
\end{defn}

It is really a category:

\begin{proof}
  We need to prove that: composition of morphisms is a morphism, composition
  is associative, and identity morphisms can be canceled on the left and on
  the right.

  That composition of morphisms is a morphism follows from these implications:
  \[ f \circ a \sqsubseteq b \circ f \wedge g \circ b \sqsubseteq c \circ g
     \Rightarrow g \circ f \circ a \sqsubseteq g \circ b \circ f \sqsubseteq c
     \circ g \circ f. \]
  That composition is associative is obvious.

  That identity morphisms can be canceled on the left and on the right is
  obvious.
\end{proof}

\begin{rem}
  The ``physical'' meaning of this category is:
  \begin{itemize}
    \item Objects (endomorphisms of $C$) are spaces.

    \item Morphisms are continuous functions between spaces.

    \item $f \circ a \sqsubseteq b \circ f$ intuitively means that $f$
    combined with an infinitely small is less than infinitely small combined
    with $f$ (that is $f$ is continuous).
  \end{itemize}
\end{rem}

\begin{rem}
  Every $\Hom (\mathfrak{A}, \mathfrak{B})$ of $\mathbf{Pos}$
  is partially ordered by the formula $a \leqslant b \Leftrightarrow \forall x
  \in \mathfrak{A}: a (x) \leqslant b (x)$. So $\cont
  (\mathbf{Pos})$ is defined.
\end{rem}

\begin{defn}
  I call a $\mathbf{Pos}$-morphism \emph{monovalued} when it maps
  atoms to atoms or least element.
\end{defn}

\begin{defn}
  I call a $\mathbf{Pos}$-morphism \emph{entirely defined} when
  its value is non-least on every non-least element.
\end{defn}

\begin{obvious}
A morphism is both monovalued and entirely defined iff it maps atoms into
atoms.
\end{obvious}

\fxnote{Show how it relates with dagger categories.}

\begin{defn}
  $\mathbf{mePos}$ is the subcategory of $\mathbf{Pos}$ with
  only monovalued and entirely defined morphisms.
\end{defn}

\begin{obvious}
This is a well defined category.{\hspace*{\fill}}{\medskip}
\end{obvious}

\begin{defn}
  $\mathbf{mefp} \mathsf{FCD}$ is the subcategory of
  $\mathbf{fp} \mathsf{FCD}$ with only monovalued and entirely
  defined morphisms.
\end{defn}

\begin{rem}
  In the two above definitions different definitions of monovaluedness and
  entire definedness from different articles.
\end{rem}

\section{Definition of the categories}

\begin{defn}
  A \emph{(pointfree) endo-funcoid} is a (pointfree) funcoid with the same
  source and destination (an endomorphism of the category of (pointfree)
  funcoids). I will denote $\Ob f$ the object of an endomorphism $f$.
\end{defn}

\begin{obvious}
The \emph{category of continuous pointfree funcoids} $\cont
(\mathbf{fp} \mathsf{FCD})$ is:
\begin{itemize}
  \item Objects are small pointfree endo-funcoids.

  \item Morphisms from an object $a$ to an object $b$ are triples $(f , a ,
  b)$ where $f$ is a pointfree funcoid from $\Ob a$ to $\Ob b$
  such that $f$ is a continuous morphism from $a$ to $b$ (that is $f \circ a
  \sqsubseteq b \circ f$, or equivalently $a \sqsubseteq f^{- 1} \circ b \circ
  f$, or equivalently $f \circ a \circ f^{- 1} \sqsubseteq f$).

  \item Composition is the composition of pointfree funcoids.

  \item Identity for an object $a$ is $(I^{\mathsf{FCD}}_{\Ob a}
  , a , a)$.
\end{itemize}
\end{obvious}

\section{Isomorphisms}

\begin{thm}
  If $f$ is an isomorphism $a \rightarrow b$ of the category
  $\cont (\mathbf{fp}
  \mathsf{FCD})$, then:
  \begin{enumerate}
    \item $f \circ a = b \circ f$;

    \item $a = f^{- 1} \circ b \circ f$;

    \item $f \circ a \circ f^{- 1} = b$.
  \end{enumerate}
\end{thm}

\begin{proof}
  Note that $f$ is monovalued and entirely defined.

  1. We have $f \circ a \sqsubseteq b \circ f$ and $f^{- 1} \circ b
  \sqsubseteq a \circ f^{- 1}$. Consequently $f^{- 1} \circ f \circ a
  \sqsubseteq f^{- 1} \circ b \circ f$; $a \sqsubseteq f^{- 1} \circ b \circ
  f$; $a \circ f^{- 1} \sqsubseteq f^{- 1} \circ b \circ f \circ f^{- 1}$; $a
  \circ f^{- 1} \sqsubseteq f^{- 1} \circ b$. Similarly $b \circ f \sqsubseteq
  f \circ a$. So $f \circ a = b \circ f$.

  2 and 3. Follow from the definition of isomorphism.
\end{proof}

Isomorphisms are meant to preserve structure of objects. I will show that
(under certain conditions) isomorphisms of $\cont
(\mathbf{fp} \mathsf{FCD})$ really preserve
structure of objects.

First we will consider an isomorphism between objects $a$ and $b$ which are
funcoids (not the general case of pointfree funcoids). In this case a map
which preserves structure of objects is a \emph{bijection}. It is really a
bijection as the following theorem says:

\begin{thm}
If $f$ is an isomorphism of the category of funcoids then $f$ is a discrete
funcoid (so, it is essentially a bijection).
\fxnote{Split it into two propositions: about completeness and co-completeness.}
\end{thm}

\begin{proof}
  $\supfun{f}^{\ast} A \sqcap \supfun{f}^{\ast} ((\Src f)
  \setminus A) = 0^{\Dst f}$ because $f$ is monovalued.

  $\supfun{f}^{\ast} A \sqcup \supfun{f}^{\ast} ((\Src f)
  \setminus A) = 1^{\Dst f}$.

  Therefore $\supfun{f}^{\ast} A$ is a principal filter (theorem 49 in
  {\cite{filters}}). So $f$ is co-complete.

  That $f$ is complete follows from symmetry.
\end{proof}

For wider class of pointfree funcoids the concept of bijection does not make
sense. Instead we would want a structure preserving map to be \emph{order
isomorphism}.

Actually, for mapping between $\subsets A$ and $\subsets B$ where $A$
and $B$ are some sets (including the above considered case of funcoids from
$A$ to $B$) bijection and order isomorphism are essentially the same:

\begin{prop}
  Bijections $F$ between sets $A$ and $B$ bijectively correspond to order
  isomorphisms $f$ between $\subsets A$ and $\subsets B$ by the formula
  $f = \supfun{F}$.
\end{prop}

\begin{proof}
  Let $F$ is a bijection. Then $X \subseteq Y \Rightarrow \supfun{F} X
  \subseteq \supfun{F} Y$ and $\langle F^{- 1} \rangle \langle F
  \rangle X = X$ for every sets $X, Y \in \subsets A$. Thus $f = \langle F
  \rangle$ is an order isomorphism.

  Let now $f$ is an order isomorphism between $\subsets A$ and $\subsets
  B$. Then $f (\{ x \})$ is a singleton for every $x \in A$. Take $F (x)$ to
  the unique $y$ such that $f (\{ x \}) = \{ y \}$. Obviously $f$ is a
  bijection and $f = \supfun{F}$.
\end{proof}

For arbitrary pointfree funcoids isomorphisms do not necessarily preserve
structure. It holds only for \emph{increasing pointfree funcoids}:

\begin{defn}
  I call a pointfree funcoid $f$ \emph{increasing} iff $\supfun{f}$
  and $\langle f^{- 1} \rangle$ are monotone functions.
\end{defn}

\begin{prop}
  If $f$ is an increasing isomorphism of the category of pointfree funcoids
  then $\supfun{f}$ is an order isomorphism.
\end{prop}

\begin{proof}
  We have: $\supfun{f} \circ \langle f^{- 1} \rangle = \langle f \circ
  f^{- 1} \rangle = \langle \id^{\mathsf{FCD}}_{\mathfrak{B}}
  \rangle = \id_{\mathfrak{B}}$ and $\langle f^{- 1} \rangle \circ
  \supfun{f} = \langle f^{- 1} \circ f \rangle = \langle
  \id^{\mathsf{FCD}}_{\mathfrak{A}} \rangle =
  \id_{\mathfrak{A}}$. Thus $\supfun{f}$ is a bijection.

  $\supfun{f}$ is increasing and bijective.
\end{proof}

\begin{rem}
  Non-increasing isomorphisms of the category of pointfree funcoids are
  against sound mind, they don't preserve the structure of the source, that is
  for them $\supfun{f}$ or $\langle f^{- 1} \rangle$ are not order
  isomorphisms.
\end{rem}

\begin{obvious}
Isomorphisms of $\cont (\mathbf{Pos})$ and
$\cont (\mathbf{mePos})$ are order
isomorphisms.
\end{obvious}

\section{Direct products}

\fxerror{Now this section is a complete mess. Clean it up.}

Consider the category $\mathbf{contFcd}$ which is the full
subcategory $\cont (\mathbf{mePos})$ restricted to
objects which are essentially increasing pointfree funcoids.

Let $f_1 : Y \rightarrow X_1$ and $f_2 : Y \rightarrow X_2$ are morphisms of
$\mathbf{contFcd}$.

The product object is $X_1 \times^{(C)} X_2$ (cross composition product of
funcoids used). It is easy to see that $X_1 \times^{(C)} X_2$ is an object of
$\mathbf{contFcd}$ that is an endo-funcoid.

The morphism $f_1 \times^{(D)} f_2 : Y \rightarrow X_1 \times^{(C)} X_2$ is
defined by the formula $(f_1 \times^{(D)} f_2) y = f_1 y
\times^{\mathsf{FCD}} f_2 y$.

$f_1 \times^{(D)} f_2$ is monovalued and entirely defined because so are $f_1$
and $f_2$.
\[ (f_1 \times^{(D 2)} f_2) y = \bigcup \left\{ f_1 Y
   \times^{\mathsf{FCD}} f_2 Y \hspace{1em} | \hspace{1em} Y \in
   \atoms^{\mathfrak{A}} y \right\} . \]

\fxnote{Is $(f_1 \times^{(D 2)} f_2)$ a pointfree funcoid?}

To prove that it is really a morphism we need to show
\[ (f_1 \times^{(D)} f_2) \circ Y \sqsubseteq (X_1 \times^{(C)} X_2) \circ
   (f_1 \times^{(D)} f_2) \]
that is (for every $y$)
\[ (f_1 \times^{(D)} f_2) Y y \sqsubseteq (X_1 \times^{(C)} X_2) (f_1
   \times^{(D)} f_2) y. \]
Really, $(f_1 \times^{(D)} f_2) Y y = f_1 Y y \times^{\mathsf{FCD}} f_2
Y y$;

$(X_1 \times^{(C)} X_2) (f_1 \times^{(D)} f_2) y = (X_1 \times^{(C)} X_2) (f_1
y \times^{\mathsf{FCD}} f_2 y) = X_1 f_1 y \times^{\mathsf{FCD}}
X_2 f_2 y$;

but it is easy to show $f_1 Y y \times^{\mathsf{FCD}} f_2 Y y
\sqsubseteq X_1 f_1 y \times^{\mathsf{FCD}} X_2 f_2 y$.

??

I define ??

\fxnote{Prove that it is a direct product in $\mathbf{contFcd}$.}


\section{Prob 2. b)}

Fig. \ref{fig:fig3} shows log-log plot of single points for $n(10^{-4})$, $n(10^{-2})$, $n(10^{-1})$, $n(1)$ and $n(5)$ withan axis range from $x=10^{-4}$ to $x_{max}=5$  and corresponding interpolation.
\lstinputlisting{interpolation.py}

\begin{figure}[ht!]
  \centering
  \includegraphics[width=0.9\linewidth]{./plots/interpolation.png}
  \caption{Log-log Plot of $n(x)$ and its interpolation.}
  \label{fig:fig3}
\end{figure}

Output of $x$ and $n(x)$.

\lstinputlisting{density_profile.txt}


% Copyright 2018 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\section{Constructing Paths}

\subsection{Overview}

The ``basic entity of drawing'' in \pgfname\ is the \emph{path}. A path
consists of several parts, each of which is either a closed or open curve. An
open curve has a starting point and an end point and, in between, consists of
several \emph{segments}, each of which is either a straight line or a Bézier
curve. Here is an example of a path (in red) consisting of two parts, one open,
one closed:
%
\begin{codeexample}[]
\begin{tikzpicture}[scale=2]
  \draw[thick,red]
       (0,0) coordinate (a)
    -- coordinate (ab) (1,.5) coordinate (b)
    .. coordinate (bc) controls +(up:1cm) and +(left:1cm) .. (3,1)  coordinate (c)
       (0,1) -- (2,1) -- coordinate (x) (1,2) -- cycle;

  \draw (a)  node[below] {start part 1}
        (ab) node[below right] {straight segment}
        (b)  node[right] {end first segment}
        (c)  node[right] {end part 1}
        (x)  node[above right]  {part 2 (closed)};
\end{tikzpicture}
\end{codeexample}

A path, by itself, has no ``effect'', that is, it does not leave any marks on
the page. It is just a set of points on the plane. However, you can \emph{use}
a path in different ways. The most natural actions are \emph{stroking} (also
known as \emph{drawing}) and \emph{filling}. Stroking can be imagined as
picking up a pen of a certain diameter and ``moving it along the path''.
Filling means that everything ``inside'' the path is filled with a uniform
color. Naturally, the open parts of a path must first be closed before a path
can be filled.

In \pgfname, there are numerous commands for constructing paths, all of which
start with |\pgfpath|. There are also commands for \emph{using} paths, though
most operations can be performed by calling |\pgfusepath| with an appropriate
parameter.

As a side-effect, the path construction commands keep track of two bounding
boxes. One is the bounding box for the current path, the other is a bounding
box for all paths in the current picture. See Section~\ref{section-bb} for more
details.

Each path construction command extends the current path in some way. The
``current path'' is a global entity that persists across \TeX\ groups. Thus,
between calls to the path construction commands you can perform arbitrary
computations and even open and close \TeX\ groups. The current path only gets
``flushed'' when the |\pgfusepath| command is called (or when the soft-path
subsystem is used directly, see Section~\ref{section-soft-paths}).

\subsection{The Move-To Path Operation}

The most basic operation is the move-to operation. It must be given at the
beginning of paths, though some path construction command (like
|\pgfpathrectangle|) generate move-tos implicitly. A move-to operation can also
be used to start a new part of a path.

\begin{command}{\pgfpathmoveto\marg{coordinate}}
    This command expects a \pgfname-coordinate like |\pgfpointorigin| as its
    parameter. When the current path is empty, this operation will start the
    path at the given \meta{coordinate}. If a path has already been partly
    constructed, this command will end the current part of the path and start a
    new one.
    %
\begin{codeexample}[]
\begin{pgfpicture}
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpathlineto{\pgfpoint{1cm}{1cm}}
  \pgfpathlineto{\pgfpoint{2cm}{1cm}}
  \pgfpathlineto{\pgfpoint{3cm}{0.5cm}}
  \pgfpathlineto{\pgfpoint{3cm}{0cm}}
  \pgfsetfillcolor{yellow!80!black}
  \pgfusepath{fill,stroke}
\end{pgfpicture}
\end{codeexample}
    %
\begin{codeexample}[]
\begin{pgfpicture}
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpathlineto{\pgfpoint{1cm}{1cm}}
  \pgfpathlineto{\pgfpoint{2cm}{1cm}}
  \pgfpathmoveto{\pgfpoint{2cm}{1cm}} % New part
  \pgfpathlineto{\pgfpoint{3cm}{0.5cm}}
  \pgfpathlineto{\pgfpoint{3cm}{0cm}}
  \pgfsetfillcolor{yellow!80!black}
  \pgfusepath{fill,stroke}
\end{pgfpicture}
\end{codeexample}
    %
    The command will apply the current coordinate transformation matrix to
    \meta{coordinate} before using it.

    It will update the bounding box of the current path and picture, if
    necessary.
\end{command}

\subsection{The Line-To Path Operation}

\begin{command}{\pgfpathlineto\marg{coordinate}}
    This command extends the current path in a straight line to the given
    \meta{coordinate}. If this command is given at the beginning of path
    without any other path construction command given before (in particular
    without a move-to operation), the \TeX\ file may compile without an error
    message, but a viewer application may display an error message when trying
    to render the picture.
    %
\begin{codeexample}[]
\begin{pgfpicture}
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpathlineto{\pgfpoint{1cm}{1cm}}
  \pgfpathlineto{\pgfpoint{2cm}{1cm}}
  \pgfsetfillcolor{yellow!80!black}
  \pgfusepath{fill,stroke}
\end{pgfpicture}
\end{codeexample}
    %
    The command will apply the current coordinate transformation matrix to
    \meta{coordinate} before using it.

    It will update the bounding box of the current path and picture, if
    necessary.
\end{command}

\subsection{The Curve-To Path Operations}

\begin{command}{\pgfpathcurveto\marg{support 1}\marg{support 2}\marg{coordinate}}
    This command extends the current path with a Bézier curve from the last
    point of the path to  \meta{coordinate}. The \meta{support 1} and
    \meta{support 2} are the first and second support point of the Bézier
    curve. For more information on Bézier curves, please consult a standard
    textbook on computer graphics.

    Like the line-to command, this command may not be the first path
    construction command in a path.
\begin{codeexample}[]
\begin{pgfpicture}
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpathcurveto
    {\pgfpoint{1cm}{1cm}}{\pgfpoint{2cm}{1cm}}{\pgfpoint{3cm}{0cm}}
  \pgfsetfillcolor{yellow!80!black}
  \pgfusepath{fill,stroke}
\end{pgfpicture}
\end{codeexample}
    %
    The command will apply the current coordinate transformation matrix to
    \meta{coordinate} before using it.

    It will update the bounding box of the current path and picture, if
    necessary. However, the bounding box is simply made large enough such that
    it encompasses all of the support points and the \meta{coordinate}. This
    will guarantee that the curve is completely inside the bounding box, but
    the bounding box will typically be quite a bit too large. It is not clear
    (to me) how this can be avoided without resorting to ``some serious math''
    in order to calculate a precise bounding box.
\end{command}

\begin{command}{\pgfpathquadraticcurveto\marg{support}\marg{coordinate}}
    This command works like |\pgfpathcurveto|, only it uses a quadratic Bézier
    curve rather than a cubic one. This means that only one support point is
    needed.
    %
\begin{codeexample}[]
\begin{pgfpicture}
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpathquadraticcurveto
    {\pgfpoint{1cm}{1cm}}{\pgfpoint{2cm}{0cm}}
  \pgfsetfillcolor{yellow!80!black}
  \pgfusepath{fill,stroke}
\end{pgfpicture}
\end{codeexample}
    %
    Internally, the quadratic curve is converted into a cubic curve. The only
    noticeable effect of this is that the points used for computing the
    bounding box are the control points of the converted curve rather than
    \meta{support}. The main effect of this is that the bounding box will be a
    bit tighter than might be expected. In particular, \meta{support} will not
    always be part of the bounding box.
\end{command}

There exist two commands to draw only part of a cubic Bézier curve:

\begin{command}{\pgfpathcurvebetweentime\marg{time $t_1$}\marg{time $t_2$}\marg{point p}\marg{point $s_1$}\marg{point $s_2$}\marg{point q}}
    This command draws the part of the curve described by $p$, $s_1$, $s_2$ and
    $q$ between the times $t_1$ and $t_2$. A time value of 0 indicates the
    point $p$ and a time value of 1 indicates point $q$. This command includes
    a moveto operation to the first point.
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \draw [thin] (0,0) .. controls (0,2) and (3,0) .. (3,2);
  \pgfpathcurvebetweentime{0.25}{0.9}{\pgfpointxy{0}{0}}{\pgfpointxy{0}{2}}
    {\pgfpointxy{3}{0}}{\pgfpointxy{3}{2}}
  \pgfsetstrokecolor{red}
  \pgfsetstrokeopacity{0.5}
  \pgfsetlinewidth{2pt}
  \pgfusepath{stroke}
\end{tikzpicture}
\end{codeexample}
    %
\end{command}

\begin{command}{\pgfpathcurvebetweentimecontinue\marg{time $t_1$}\marg{time $t_2$}\marg{point p}\marg{point $s_1$}\marg{point $s_2$}\marg{point q}}
    This command works like |\pgfpathcurvebetweentime|, except that a moveto
    operation is \emph{not} made to the first point.
\end{command}

\subsection{The Close Path Operation}

\begin{command}{\pgfpathclose}
    This command closes the current part of the path by appending a straight
    line to the start point of the current part. Note that there \emph{is} a
    difference between closing a path and using the line-to operation to add a
    straight line to the start of the current path. The difference is
    demonstrated by the upper corners of the triangles in the following
    example:
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,2);
  \pgfsetlinewidth{5pt}
  \pgfpathmoveto{\pgfpoint{1cm}{1cm}}
  \pgfpathlineto{\pgfpoint{0cm}{-1cm}}
  \pgfpathlineto{\pgfpoint{1cm}{-1cm}}
  \pgfpathclose
  \pgfpathmoveto{\pgfpoint{2.5cm}{1cm}}
  \pgfpathlineto{\pgfpoint{1.5cm}{-1cm}}
  \pgfpathlineto{\pgfpoint{2.5cm}{-1cm}}
  \pgfpathlineto{\pgfpoint{2.5cm}{1cm}}
  \pgfusepath{stroke}
\end{tikzpicture}
\end{codeexample}
    %
\end{command}

\subsection{Arc, Ellipse and Circle Path Operations}

The path construction commands that we have discussed up to now are sufficient
to create all paths that can be created ``at all''. However, it is useful to
have special commands to create certain shapes, like circles, that arise often
in practice.

In the following, the commands for adding (parts of) (transformed) circles to a
path are described.

\begin{command}{\pgfpatharc\marg{start angle}\marg{end angle}{\ttfamily\char`\{}\meta{radius}\opt{| and |\meta{y-radius}}{\ttfamily\char`\}}}
    This command appends a part of a circle (or an ellipse) to the current
    path. Imagine the curve between \meta{start angle} and \meta{end angle} on
    a circle of radius \meta{radius} (if $\meta{start angle} < \meta{end
    angle}$, the curve goes around the circle counterclockwise, otherwise
    clockwise). This curve is now moved such that the point where the curve
    starts is the previous last point of the path. Note that this command will
    \emph{not} start a new part of the path, which is important for example for
    filling purposes.
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,2);
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpathlineto{\pgfpoint{0cm}{1cm}}
  \pgfpatharc{180}{90}{.5cm}
  \pgfpathlineto{\pgfpoint{3cm}{1.5cm}}
  \pgfpatharc{90}{-45}{.5cm}
  \pgfusepath{fill}
\end{tikzpicture}
\end{codeexample}

    Saying |\pgfpatharc{0}{360}{1cm}| ``nearly'' gives you a full circle. The
    ``nearly'' refers to the fact that the circle will not be closed. You can
    close it using |\pgfpathclose|.

    If the optional \meta{y-radius} is given, the \meta{radius} is the
    $x$-radius and the \meta{y-radius} the $y$-radius of the ellipse from which
    the curve is taken:
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,2);
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpatharc{180}{45}{2cm and 1cm}
  \pgfusepath{draw}
\end{tikzpicture}
\end{codeexample}

    The axes of the circle or ellipse from which the arc is ``taken'' always
    point up and right. However, the current coordinate transformation matrix
    will have an effect on the arc. This can be used to, say, rotate an arc:
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,2);
  \pgftransformrotate{30}
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpatharc{180}{45}{2cm and 1cm}
  \pgfusepath{draw}
\end{tikzpicture}
\end{codeexample}

    The command will update the bounding box of the current path and picture,
    if necessary. Unless rotation or shearing transformations are applied, the
    bounding box will be tight.
\end{command}

\begin{command}{\pgfpatharcaxes\marg{start angle}\marg{end angle}\marg{first axis}\marg{second axis}}
    This command is similar to |\pgfpatharc|. The main difference is how the
    ellipse or circle is specified from which the arc is taken. The two
    parameters \meta{first axis} and \meta{second axis} are the $0^\circ$-axis
    and the $90^\circ$-axis of the ellipse from which the path is taken. Thus,
    |\pgfpatharc{0}{90}{1cm and 2cm}| has the same effect as
    %
\begin{verbatim}
\pgfpatharcaxes{0}{90}{\pgfpoint{1cm}{0cm}}{\pgfpoint{0cm}{2cm}}
\end{verbatim}
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,2);
  \draw (0,0) -- (2cm,5mm) (0,0) -- (0cm,1cm);

  \pgfpathmoveto{\pgfpoint{2cm}{5mm}}
  \pgfpatharcaxes{0}{90}{\pgfpoint{2cm}{5mm}}{\pgfpoint{0cm}{1cm}}
  \pgfusepath{draw}
\end{tikzpicture}
\end{codeexample}
    %
\end{command}

\begin{command}{\pgfpatharcto\marg{x-radius}\marg{y-radius}\marg{rotation} \marg{large arc flag}\marg{counterclockwise flag}\\\marg{target point}}
    This command (which directly corresponds to the arc-path command of
    \textsc{svg}) is used to add an arc to the path that starts at the current
    point and ends at \meta{target point}. This arc is part of an ellipse that
    is determined in the following way: Imagine an ellipse with radii
    \meta{x-radius} and \meta{y-radius} that is rotated around its center by
    \meta{rotation} degrees. When you move this ellipse around in the plane,
    there will be exactly two positions such that the two current point and the
    target point lie on the border of the ellipse (excluding pathological
    cases). The flags \meta{large arc flag} and \meta{clockwise flag} are then
    used to decide which of these ellipses should be picked and which arc on
    the picked ellipsis should be used.
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,2);

  \pgfpathmoveto{\pgfpoint{0mm}{20mm}}
  \pgfpatharcto{3cm}{1cm}{0}{0}{0}{\pgfpoint{3cm}{1cm}}
  \pgfusepath{draw}
\end{tikzpicture}
\end{codeexample}
    %
    Both flags are considered to be false exactly if they evaluate to |0|,
    otherwise they are true. If the \meta{large arc flag} is true, then the
    angle spanned by the arc will be greater than $180^\circ$, otherwise it
    will be less than $180^\circ$. The \meta{clockwise flag} is used to
    determine which of the two ellipses should be used: if the flag is true,
    then the arc goes from the current point to the target point in a
    counterclockwise direction, otherwise in a clockwise fashion.
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \pgfsetlinewidth{2pt}
  % Flags 0 0: red
  \pgfsetstrokecolor{red}
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpatharcto{20pt}{10pt}{0}{0}{0}{\pgfpoint{20pt}{10pt}}
  \pgfusepath{stroke}
  % Flags 0 1: blue
  \pgfsetstrokecolor{blue}
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpatharcto{20pt}{10pt}{0}{0}{1}{\pgfpoint{20pt}{10pt}}
  \pgfusepath{stroke}
  % Flags 1 0: orange
  \pgfsetstrokecolor{orange}
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpatharcto{20pt}{10pt}{0}{1}{0}{\pgfpoint{20pt}{10pt}}
  \pgfusepath{stroke}
  % Flags 1 1: black
  \pgfsetstrokecolor{black}
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpatharcto{20pt}{10pt}{0}{1}{1}{\pgfpoint{20pt}{10pt}}
  \pgfusepath{stroke}
\end{tikzpicture}
\end{codeexample}
    %
    \emph{Warning:} The internal computations necessary for this command are
    numerically very unstable. In particular, the arc will not always really
    end at the \meta{target coordinate}, but may be off by up to several
    points. A more precise positioning is currently infeasible due to \TeX's
    numerical weaknesses. The only case it works quite nicely is when the
    resulting angle is a multiple of~$90^\circ$.
\end{command}

\begin{command}{\pgfpatharctoprecomputed\marg{center point}\marg{start angle}\marg{end angle}\marg{end point}\\\marg{x-radius}\marg{y-radius}\marg{ratio x-radius/y-radius}\marg{ratio y-radius/x-radius}}
    A specialized arc operation which is fast and numerically stable, provided
    a lot of information is given in advance.

    In contrast to |\pgfpatharc|, it explicitly interpolates start and end
    points.

    In contrast to |\pgfpatharcto|, this routine is numerically stable and
    quite fast since it relies on a lot of available information.
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,2);

  \def\cx{1.5cm}% center x
  \def\cy{1cm}% center y
  \def\startangle{0}%
  \def\endangle{270}%
  \def\a{1.5cm}% xradius
  \def\b{0.5cm}% yradius
  \pgfmathparse{\a/\b}\let\abratio=\pgfmathresult
  \pgfmathparse{\b/\a}\let\baratio=\pgfmathresult
  %
  % start point:
  \pgfpathmoveto{\pgfpoint{\cx+\a*cos(\startangle)}{\cy+\b*sin(\startangle)}}%
  \pgfpatharctoprecomputed
    {\pgfpoint{\cx}{\cy}}
    {\startangle}
    {\endangle}
    {\pgfpoint{\cx+\a*cos(\endangle)}{\cy+\b*sin(\endangle)}}% end point
    {\a}
    {\b}
    {\abratio}
    {\baratio}
  \pgfusepath{draw}
\end{tikzpicture}
\end{codeexample}

    \begin{command}{\pgfpatharctomaxstepsize}
        The quality of arc approximation taken by |\pgfpatharctoprecomputed| by
        means of Bézier splines is controlled by a mesh width, which is
        initially

        |\def\pgfpatharctoprecomputed{45}|.

        The mesh width is provided in (full!) degrees. The smaller the mesh
        width, the more precise the arc approximation.

        Use an empty value to disable spline approximation (uses a single cubic
        polynomial for the complete arc).

        The value must be an integer!
    \end{command}
\end{command}

\begin{command}{\pgfpathellipse\marg{center}\marg{first axis}\marg{second axis}}
    The effect of this command is to append an ellipse to the current path (if
    the path is not empty, a new part is started). The ellipse's center will be
    \meta{center} and \meta{first axis} and \meta{second axis} are the axis
    \emph{vectors}. The same effect as this command can also be achieved using
    an appropriate sequence of move-to, arc, and close operations, but this
    command is easier and faster.
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,2);
  \pgfpathellipse{\pgfpoint{1cm}{0cm}}
                 {\pgfpoint{1.5cm}{0cm}}
                 {\pgfpoint{0cm}{1cm}}
  \pgfusepath{draw}
  \color{red}
  \pgfpathellipse{\pgfpoint{1cm}{0cm}}
                 {\pgfpoint{1cm}{1cm}}
                 {\pgfpoint{-0.5cm}{0.5cm}}
  \pgfusepath{draw}
\end{tikzpicture}
\end{codeexample}

    The command will apply coordinate transformations to all coordinates of the
    ellipse. However, the coordinate transformations are applied only after the
    ellipse is ``finished conceptually''. Thus, a transformation of 1cm to the
    right will simply shift the ellipse one centimeter to the right; it will
    not add 1cm to the $x$-coordinates of the two axis vectors.

    The command will update the bounding box of the current path and picture,
    if necessary.
\end{command}

\begin{command}{\pgfpathcircle\marg{center}\marg{radius}}
    A shorthand for |\pgfpathellipse| applied to \meta{center} and the two axis
    vectors $(\meta{radius},0)$ and $(0,\meta{radius})$.
\end{command}

\subsection{Rectangle Path Operations}

Another shape that arises frequently is the rectangle. Two commands can be used
to add a rectangle to the current path. Both commands will start a new part of
the path.

\begin{command}{\pgfpathrectangle\marg{corner}\marg{diagonal vector}}
    Adds a rectangle to the path whose one corner is \meta{corner} and whose
    opposite corner is given by $\meta{corner} + \meta{diagonal vector}$.
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,2);
  \pgfpathrectangle{\pgfpoint{1cm}{0cm}}{\pgfpoint{1.5cm}{1cm}}
  \pgfpathrectangle{\pgfpoint{1.5cm}{0.25cm}}{\pgfpoint{1.5cm}{1cm}}
  \pgfpathrectangle{\pgfpoint{2cm}{0.5cm}}{\pgfpoint{1.5cm}{1cm}}
  \pgfusepath{draw}
\end{tikzpicture}
\end{codeexample}
    %
    The command will apply coordinate transformations and update the bounding
    boxes tightly.
\end{command}

\begin{command}{\pgfpathrectanglecorners\marg{corner}\marg{opposite corner}}
    Adds a rectangle to the path whose two opposing corners are \meta{corner}
    and \meta{opposite corner}.
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,2);
  \pgfpathrectanglecorners{\pgfpoint{1cm}{0cm}}{\pgfpoint{1.5cm}{1cm}}
  \pgfusepath{draw}
\end{tikzpicture}
\end{codeexample}
    %
    The command will apply coordinate transformations and update the bounding
    boxes tightly.
\end{command}

\subsection{The Grid Path Operation}

\begin{command}{\pgfpathgrid\oarg{options}\marg{first corner}\marg{second corner}}
    Appends a grid to the current path. That is, a (possibly large) number of
    parts are added to the path, each part consisting of a single horizontal or
    vertical straight line segment.

    Conceptually, the origin is part of the grid and the grid is clipped to the
    rectangle specified by the \meta{first corner} and the \meta{second
    corner}. However, no clipping occurs (this command just adds parts to the
    current path) and the points where the lines enter and leave the ``clipping
    area'' are computed and used to add simple lines to the current path.

    The following keys influence the grid:
    %
    \begin{key}{/pgf/stepx=\meta{dimension} (initially 1cm)}
        The horizontal stepping.
    \end{key}
    %
    \begin{key}{/pgf/stepy=\meta{dimension} (initially 1cm)}
        The vertical stepping.
    \end{key}
    %
    \begin{key}{/pgf/step=\meta{vector}}
        Sets the horizontal stepping to the $x$-coordinate of \meta{vector} and
        the vertical stepping to its $y$-coordinate.
    \end{key}
    %
\begin{codeexample}[]
\begin{pgfpicture}
  \pgfsetlinewidth{0.8pt}
  \pgfpathgrid[step={\pgfpoint{1cm}{1cm}}]
    {\pgfpoint{-3mm}{-3mm}}{\pgfpoint{33mm}{23mm}}
  \pgfusepath{stroke}
  \pgfsetlinewidth{0.4pt}
  \pgfpathgrid[stepx=1mm,stepy=1mm]
    {\pgfpoint{-1.5mm}{-1.5mm}}{\pgfpoint{31.5mm}{21.5mm}}
  \pgfusepath{stroke}
\end{pgfpicture}
\end{codeexample}
    %
    The command will apply coordinate transformations and update the bounding
    boxes. As for ellipses, the transformations are applied to the
    ``conceptually finished'' grid.
    %
\begin{codeexample}[]
\begin{pgfpicture}
  \pgftransformrotate{10}
  \pgfpathgrid[stepx=1mm,stepy=2mm]{\pgfpoint{0mm}{0mm}}{\pgfpoint{30mm}{30mm}}
  \pgfusepath{stroke}
\end{pgfpicture}
\end{codeexample}
    %
\end{command}

\subsection{The Parabola Path Operation}

\begin{command}{\pgfpathparabola\marg{bend vector}\marg{end vector}}
    This command appends two half-parabolas to the  current path. The first
    starts at the current point and ends at the current point plus \meta{bend
    vector}. At this point, it has its bend. The second half parabola starts at
    that bend point and ends at point that is given by the bend plus \meta{end
    vector}.

    If you set \meta{end vector} to the null vector, you append only a half
    parabola that goes from the current point to the bend; by setting
    \meta{bend vector} to the null vector, you append only a half parabola that
    goes through the current point and \meta{end vector} and has its bend at
    the current point.

    It is not possible to use this command to draw a part of a parabola that
    does not contain the bend.
    %
\begin{codeexample}[]
\begin{pgfpicture}
  % Half-parabola going ``up and right''
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpathparabola{\pgfpointorigin}{\pgfpoint{2cm}{4cm}}
  \color{red}
  \pgfusepath{stroke}

  % Half-parabola going ``down and right''
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpathparabola{\pgfpoint{-2cm}{4cm}}{\pgfpointorigin}
  \color{blue}
  \pgfusepath{stroke}

  % Full parabola
  \pgfpathmoveto{\pgfpoint{-2cm}{2cm}}
  \pgfpathparabola{\pgfpoint{1cm}{-1cm}}{\pgfpoint{2cm}{4cm}}
  \color{orange}
  \pgfusepath{stroke}
\end{pgfpicture}
\end{codeexample}
    %
    The command will apply coordinate transformations and update the bounding
    boxes.
\end{command}

\subsection{Sine and Cosine Path Operations}

Sine and cosine curves often need to be drawn and the following commands may
help with this. However, they only allow you to append sine and cosine curves
in intervals that are multiples of $\pi/2$.

\begin{command}{\pgfpathsine\marg{vector}}
    This command appends a sine curve in the interval $[0,\pi/2]$ to the
    current path. The sine curve is squeezed or stretched such that the curve
    starts at the current point and ends at the current point plus
    \meta{vector}.
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,1);
  \pgfpathmoveto{\pgfpoint{1cm}{0cm}}
  \pgfpathsine{\pgfpoint{1cm}{1cm}}
  \pgfusepath{stroke}

  \color{red}
  \pgfpathmoveto{\pgfpoint{1cm}{0cm}}
  \pgfpathsine{\pgfpoint{-2cm}{-2cm}}
  \pgfusepath{stroke}
\end{tikzpicture}
\end{codeexample}
    %
    The command will apply coordinate transformations and update the bounding
    boxes.
\end{command}

\begin{command}{\pgfpathcosine\marg{vector}}
    This command appends a cosine curve in the interval $[0,\pi/2]$ to the
    current path. The curve is squeezed or stretched such that the curve starts
    at the current point and ends at the current point plus \meta{vector}.
    Using several sine and cosine operations in sequence allows you to produce
    a complete sine or cosine curve
    %
\begin{codeexample}[]
\begin{pgfpicture}
  \pgfpathmoveto{\pgfpoint{0cm}{0cm}}
  \pgfpathsine{\pgfpoint{1cm}{1cm}}
  \pgfpathcosine{\pgfpoint{1cm}{-1cm}}
  \pgfpathsine{\pgfpoint{1cm}{-1cm}}
  \pgfpathcosine{\pgfpoint{1cm}{1cm}}
  \pgfsetfillcolor{yellow!80!black}
  \pgfusepath{fill,stroke}
\end{pgfpicture}
\end{codeexample}
    %
    The command will apply coordinate transformations and update the bounding
    boxes.
\end{command}

\subsection{Plot Path Operations}

There exist several commands for appending plots to a path. These commands are
available through the module |plot|. They are documented in
Section~\ref{section-plots}.

\subsection{Rounded Corners}

Normally, when you connect two straight line segments or when you connect two
curves that end and start ``at different angles'', you get ``sharp corners''
between the lines or curves. In some cases it is desirable to produce ``rounded
corners'' instead. Thus, the lines or curves should be shortened a bit and then
connected by arcs.

\pgfname\ offers an easy way to achieve this effect, by calling the following
two commands.

\begin{command}{\pgfsetcornersarced\marg{point}}
    This command causes all subsequent corners to be replaced by little
    arcs. The effect of this command lasts till the end of the current
    \TeX\ scope.

    The \meta{point} dictates how large the corner arc will be. Consider a
    corner made by two lines $l$ and~$r$ and assume that the line $l$ comes
    first on the path. The $x$-dimension of the \meta{point} decides by how
    much the line~$l$ will be shortened, the $y$-dimension of \meta{point}
    decides by how much the line $r$ will be shortened. Then, the shortened
    lines are connected by an arc.
    %
\begin{codeexample}[]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,2);

  \pgfsetcornersarced{\pgfpoint{5mm}{5mm}}
  \pgfpathrectanglecorners{\pgfpointorigin}{\pgfpoint{3cm}{2cm}}
  \pgfusepath{stroke}
\end{tikzpicture}
\end{codeexample}

\begin{codeexample}[]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,2);

  \pgfsetcornersarced{\pgfpoint{10mm}{5mm}}
  % 10mm entering,
  % 5mm leaving.
  \pgfpathmoveto{\pgfpointorigin}
  \pgfpathlineto{\pgfpoint{0cm}{2cm}}
  \pgfpathlineto{\pgfpoint{3cm}{2cm}}
  \pgfpathcurveto
    {\pgfpoint{3cm}{0cm}}
    {\pgfpoint{2cm}{0cm}}
    {\pgfpoint{1cm}{0cm}}
  \pgfusepath{stroke}
\end{tikzpicture}
\end{codeexample}

    If the $x$- and $y$-coordinates of \meta{point} are the same and the corner
    is a right angle, you will get a perfect quarter circle (well, not quite
    perfect, but perfect up to six decimals). When the angle is not $90^\circ$,
    you only get a fair approximation.

    More or less ``all'' corners will be rounded, even the corner generated by
    a |\pgfpathclose| command. (The author is a bit proud of this feature.)
    %
\begin{codeexample}[]
\begin{pgfpicture}
  \pgfsetcornersarced{\pgfpoint{4pt}{4pt}}
  \pgfpathmoveto{\pgfpointpolar{0}{1cm}}
  \pgfpathlineto{\pgfpointpolar{72}{1cm}}
  \pgfpathlineto{\pgfpointpolar{144}{1cm}}
  \pgfpathlineto{\pgfpointpolar{216}{1cm}}
  \pgfpathlineto{\pgfpointpolar{288}{1cm}}
  \pgfpathclose
  \pgfusepath{stroke}
\end{pgfpicture}
\end{codeexample}

    To return to normal (unrounded) corners, use
    |\pgfsetcornersarced{\pgfpointorigin}|.

    Note that the rounding will produce strange and undesirable effects if the
    lines at the corners are too short. In this case the shortening may cause
    the lines to ``suddenly extend over the other end'' which is rarely
    desirable.
\end{command}

\subsection{Internal Tracking of Bounding Boxes for Paths and Pictures}
\label{section-bb}

\makeatletter

The path construction commands keep track of two bounding boxes: One for the
current path, which is reset whenever the path is used and thereby flushed, and
a bounding box for the current |{pgfpicture}|.

\begin{command}{\pgfresetboundingbox}
    Resets the picture's bounding box. The picture will simply forget any
    previous bounding box updates and start collecting from scratch.

    You can use this together with |\pgfusepath{use as bounding box}| to
    replace the bounding box by the one of a particular path (ignoring
    subsequent paths).
\end{command}

The bounding boxes are not accessible by ``normal'' macros. Rather, two sets of
four dimension variables are used for this, all of which contain the
letter~|@|.

\begin{textoken}{\pgf@pathminx}
    The minimum $x$-coordinate ``mentioned'' in the current path. Initially,
    this is set to $16000$pt.
\end{textoken}

\begin{textoken}{\pgf@pathmaxx}
    The maximum $x$-coordinate ``mentioned'' in the current path. Initially,
    this is set to $-16000$pt.
\end{textoken}

\begin{textoken}{\pgf@pathminy}
    The minimum $y$-coordinate ``mentioned'' in the current path. Initially,
    this is set to $16000$pt.
\end{textoken}

\begin{textoken}{\pgf@pathmaxy}
    The maximum $y$-coordinate ``mentioned'' in the current path. Initially,
    this is set to $-16000$pt.
\end{textoken}

\begin{textoken}{\pgf@picminx}
    The minimum $x$-coordinate ``mentioned'' in the current picture. Initially,
    this is set to $16000$pt.
\end{textoken}

\begin{textoken}{\pgf@picmaxx}
    The maximum $x$-coordinate ``mentioned'' in the current picture. Initially,
    this is set to $-16000$pt.
\end{textoken}

\begin{textoken}{\pgf@picminy}
    The minimum $y$-coordinate ``mentioned'' in the current picture. Initially,
    this is set to $16000$pt.
\end{textoken}

\begin{textoken}{\pgf@picmaxy}
    The maximum $y$-coordinate ``mentioned'' in the current picture. Initially,
    this is set to $-16000$pt.
\end{textoken}

Each time a path construction command is called, the above variables are
(globally) updated. To facilitate this, you can use the following command:

\begin{command}{\pgf@protocolsizes\marg{x-dimension}\marg{y-dimension}}
    Updates all of the above dimensions in such a way that the point specified
    by the two arguments is inside both bounding boxes. For the picture's
    bounding box this updating occurs only if |\ifpgf@relevantforpicturesize|
    is true, see below.
\end{command}

For the bounding box of the picture it is not always desirable that every path
construction command affects this bounding box. For example, if you have just
used a clip command, you do not want anything outside the clipping area to
affect the bounding box. For this reason, there exists a special ``\TeX\ if''
that (locally) decides whether updating should be applied to the picture's
bounding box. Clipping will set this if to false, as will certain other
commands.

\begin{command}{\pgf@relevantforpicturesizefalse}
    Suppresses updating of the picture's bounding box.
\end{command}

\begin{command}{\pgf@relevantforpicturesizetrue}
    Causes updating of the picture's bounding box.
\end{command}


\section{The \reverse algorithm}
\Label{sec:reverse}

The \reverse algorithm of the \cxx Standard Library
\cite[\S 28.6.10]{cxx-17-draft} inverts the order of elements \emph{within} a sequence.
The signature of our version of \reverse reads.

\begin{lstlisting}[style=acsl-block]

  void reverse(value_type* a, size_type n);
\end{lstlisting}

\subsection{Formal specification of \reverse}

The specification for the \specref{reverse} function is shown in the following listing.

\input{Listings/reverse.h.tex}

\subsection{Implementation of \reverse}

Since the implementation of \implref{reverse} operates \emph{in place}
we use \specref{swap} in order to exchange the elements of the first half
of the array with the corresponding elements of the second half.
We reuse the predicates \logicref{Reverse} and \logicref{Unchanged}
in order to write concise loop invariants.

\input{Listings/reverse.c.tex}


\subsection{The Hausman specification test}

\subsubsection{Introduction}

The Hausman specification test allows you to choose between a fixed effects model and a random effects model.

\subsubsection{Efficiency}

Random effects models are more efficient.


\XtoCBlock{SineWave}
\label{block:SineWave}
\begin{figure}[H]\includegraphics{SineWave}\end{figure}
%\missingfigure{SineWave : SineWave.png}

\begin{XtoCtabular}{Outports}
u & Sine wave output\tabularnewline
\hline
\end{XtoCtabular}

\begin{XtoCtabular}{Mask Parameters}
Amplitude & Amplitude of wave\tabularnewline
\hline
Frequency & Frequency in Hz\tabularnewline
\hline
Offset & Offset\tabularnewline
\hline
Phase & Phase [-Pi..Pi]\tabularnewline
\hline
ts\_fact & Multiplication factor of base sampling time (in integer format)\tabularnewline
\hline
\end{XtoCtabular}

\subsubsection*{Description:}
Generation of a sine wave.

% include optional documentation file
\InputIfFileExists{\XcHomePath/Library/Audio/Doc/SineWave_Info.tex}{\vspace{1ex}}{}

\subsubsection*{Implementations:}
\begin{tabular}{l l}
\textbf{FiP8} & 8 Bit Fixed Point Implementation\tabularnewline
\textbf{FiP16} & 16 Bit Fixed Point Implementation\tabularnewline
\textbf{FiP32} & 32 Bit Fixed Point Implementation\tabularnewline
\textbf{Float32} & 32 Bit Floating Point Implementation\tabularnewline
\textbf{Float64} & 64 Bit Floating Point Implementation\tabularnewline
\end{tabular}

\XtoCImplementation{FiP8}
\nopagebreak[0]

8 Bit Fixed Point Implementation

\begin{XtoCtabular}{Outports Data Type}
u & int8\tabularnewline
\hline
\end{XtoCtabular}

\ifdefined \AddTestReports
\InputIfFileExists{\XcHomePath/Library/Audio/Doc/Test-Results/Test_SineWave_FiP8.tex}{}{}
\fi
\XtoCImplementation{FiP16}
\nopagebreak[0]

16 Bit Fixed Point Implementation

\begin{XtoCtabular}{Outports Data Type}
u & int16\tabularnewline
\hline
\end{XtoCtabular}

\ifdefined \AddTestReports
\InputIfFileExists{\XcHomePath/Library/Audio/Doc/Test-Results/Test_SineWave_FiP16.tex}{}{}
\fi
\XtoCImplementation{FiP32}
\nopagebreak[0]

32 Bit Fixed Point Implementation

\begin{XtoCtabular}{Outports Data Type}
u & int32\tabularnewline
\hline
\end{XtoCtabular}

\ifdefined \AddTestReports
\InputIfFileExists{\XcHomePath/Library/Audio/Doc/Test-Results/Test_SineWave_FiP32.tex}{}{}
\fi
\XtoCImplementation{Float32}
\nopagebreak[0]

32 Bit Floating Point Implementation

\begin{XtoCtabular}{Outports Data Type}
u & float32\tabularnewline
\hline
\end{XtoCtabular}

\ifdefined \AddTestReports
\InputIfFileExists{\XcHomePath/Library/Audio/Doc/Test-Results/Test_SineWave_Float32.tex}{}{}
\fi
\XtoCImplementation{Float64}
\nopagebreak[0]

64 Bit Floating Point Implementation

\begin{XtoCtabular}{Outports Data Type}
u & float64\tabularnewline
\hline
\end{XtoCtabular}

\ifdefined \AddTestReports
\InputIfFileExists{\XcHomePath/Library/Audio/Doc/Test-Results/Test_SineWave_Float64.tex}{}{}
\fi