\chapter{The control algorithm}
\label{ch:controlalgorithm}
Unmanned aerial vehicles (UAVs) are a class of aircraft under the control of either a remote human pilot or a on board computer. UAVs were originally developed for military purposes, although recent advances in technologies, like Li-Ion batteries and brush-less motors, have brought this type of aircraft to  others scopes of usage, like commercial, scientific and also recreational.
Although most UAVs are fixed-wing aircraft, rotorcraft are becoming popular too due to the low price and ease of maintenance and run.\graffito{Quad-copter, more commonly referred to as \emph{drones}, are commercially available to a large amateur public.} The demand for this type of drone is increasing and the global market for commercial use is expected to grow in the next few years, thats why the study case is a low-level controller for helicopters, ducted-fan tail-sitters and multi-propeller helicopters.

\section{A novel approach to the copter control proble}
A common control strategy is a cascade feedback: an outer loop for the position and an inner loop for the attitude. The inner control loop is usually composed by 3 control loop for the roll, pitch and yaw attitude angles. While this is a easy and intuitive approach to the problem, a more advanced one can be developed: the rest of this chapter describes a novel approach as presented in \autocite{marconi}.

\section{Quaternions for rotations representation}
Although the attitude has 3 degrees of freedom\graffito{Rotations of 3D objects in a 3D world can be expressed by 3 scalar quantities, usually Euler angles or roll-pitch-yaw angles (RPY).}, any minimal parametrization suffers of singularity problems (or gimbals-look).\\
\graffito{A rotation matrix is a 3x3 orto-normal matrix, so although it is composed by 9 scalar values, the matrix itself has just 3 degrees of freedom}
A very common alternative representation is rotational matrices: those do not suffer of singularities problems but are quite  redundant since 9 scalar values are used to express just 3 degrees of freedom.\\
A good trade-off between compactness and ease of representation is archived with unit quaternions, a notation that allows to represent rotations in a compact form and with no gimbals-lock problems. Another advantage to consider is numerical stability: numerical drifts make both rotation matrices and unit quaternions loose their own properties: respectively being orthonormal and having module one; it is however way easier to scale a vector than force the orthonormal structure of a matrix. More details can be found in \cite{bib:quat} and \cite{bib:rotquat}.\\
No insight in Hamiltonian math is reported there, it just follows a note about the notation used in the following chapters: in general a quaternion $q$ is given by:
\begin{equation} \label{eq:coptermodelmat}
\begin{split}
q := \begin{bmatrix}
\eta\\
\epsilon
\end{bmatrix}
\end{split}
\end{equation}
where $\eta$ is the \emph{real} component and $\epsilon$ is the \emph{pure imaginary} vector component of $q$ and the Hamilton product between 2 quaternion is indicated by the symbol $\oplus$.

\section{The copter model}
The dynamic model of the copter is given by:

\begin{equation} \label{eq:coptermodelmat}
\begin{split}
	M \ddot{p} &= -u_{f}Re_{3} + Mge_{3}\\
	\dot{R} &= RS(w)\\
	J\dot{w} &= S (Jw) w + u_{\tau}
\end{split}
\end{equation}

Where we call $ p $ the position vector of the center of gravity of the copter in the inertial reference frame $ \pazocal{F}_{i} $ and $ w $ the angular velocity of the vehicle in the body reference frame $ \pazocal{F}_{b} $. $ R $ is the rotation matrix representing the orientation of $ \pazocal{F}_{b} $ wrt $ \pazocal{F}_{i} $, $ J $ is the inertia matrix of the system and $ u_{f} $ and $ u_{\tau} $ are respectively the force and  the torque vector generated by the propellers.\graffito{Note that the while the $u_{f}$ is a scalar force which direction always aligned with the $z$ axis of $\pazocal{F}_{b}$, $u_{\tau}$ is a 3-dimensional vector.}
The $S(m)$ function generates a $3\times3$ matrix from vector $m$ such that the matrix product between $S(m)$ and another $3\times1$ vector $n$ correspond to the cross (vector) product between $m$ and $n$. $S$ can be constructed as:
\begin{equation} \label{eq:coptermodelmat}
\begin{split}
S(m) :&= \begin{bmatrix}
0 & -m_{3} & m_{2}\\
m_{3} & 0 & -m_{1}\\
-m_{2} & m_{1} & 0
\end{bmatrix}
\end{split}
\end{equation}

The copter model can be rewritten using quaternions to represent rotations by mean of the Rodriguez formula\cite{bib:rodriguez}:
\[ \pazocal{R}(q) = I + 2 \mu \pazocal{S}(\epsilon) + 2 \pazocal{S}(\epsilon)^{2}
 \]
as
\begin{equation} \label{eq:coptermodelquat}
\begin{split}
M \ddot{p} &= -u_{f}\pazocal{R}(q)e_{3} + Mge_{3}\\
\dot{q} &= \frac{1}{2} q \oplus \begin{bmatrix} 0 \\ w \end{bmatrix} \\
J\dot{w} &= S (Jw) w + u_{\tau}
\end{split}
\end{equation}

\section{Position control loop}
We can write the position error dynamic as:
\begin{equation} \label{eq:poserrdyn}
\begin{split}
M \ddot{\overline{p}} &= -u_{f}\pazocal{R}e_{3} + Mge_{3} - M\ddot{p}_{R}
\end{split}
\end{equation}
And define the control force as:
\begin{equation} \label{eq:ctrlforce}
\begin{split}
v^{c}_{R}(\ddot{p}_{R})&:=Mge_{3} - M\ddot{p}_{R}\\
v^{c}(\overline{p},\dot{\overline{p}},\ddot{p}_{R})&:=v^{c}_{R}(\ddot{p}_{R}) + \kappa(\overline{p},\dot{\overline{p}} )
\end{split}
\end{equation}
where $ \kappa(\overline{p},\dot{\overline{p}}) $ is a feedback action that can be computed as follow:
\begin{equation} \label{eq:feedback}
\begin{split}
\zeta_{1}&:=\overline{p}\\
\zeta_{2}&=\dot{\overline{p}} + \lambda_{1} \sigma (\frac{k_{1}}{\lambda_{1}}\lambda_{2})\\
\kappa(\overline{p},\dot{\overline{p}}) &:=\lambda_{2}\sigma(\frac{k_{2}}{\lambda{2}}\zeta_{2})
\end{split}
\end{equation}
where $k_{1}$, $k_{2}$, $\lambda_{1}$ and $\lambda_{2}$ are parameters to be tuned.\\
In \autoref{eq:ctrlforce} is mandatory to respect the constraint
\begin{equation} \label{eq:const}
\begin{split}
R_{R}e_{3} &= \frac{v^{c}_{R}(\ddot{p}_{R})}{\lVert v^{c}_{R}(\ddot{p}_{R})\rVert}
\end{split}
\end{equation}

The control scalar control force is than computed as:
\begin{equation} \label{eq:controlForce}
\begin{split}
u_{f} &:= \lVert v^{c}(\overline{p},\dot{\overline{p}},\ddot{p}_{R})\rVert
\end{split}
\end{equation}
\autoref{eq:controlForce} gives the total thrust the propeller should generate, however as already explained it is also necessary to compute the torque necessary to correct the vehicle attitude.\\
\autoref{sec:attControlLoop} will describe the attitude control low.

\section{Attitude control loop}\label{sec:attControlLoop}
The torque control vector is computed in a control loop nested into the position control loop, therefore, as usual in cascade control loops, it has a faster dynamic.
We start by defining the error attitude quaternion and the error angular velocity vector:
\begin{equation} \label{eq:qerr}
\begin{split}
\overline{q}&=q_{c}^{-1}\oplus q\\
\overline{w}:&=w-\overline{w}_{c}\\
\end{split}
\end{equation}
with
\begin{equation}
\begin{split}
\overline{w}_{c}:&=\pazocal{R}(\overline{q})^{T}w_{c}
\end{split}
\end{equation}
and $q_{c}$ computed as explained in \autoref{se:attSP}.

Then the control torque is given by:
\begin{equation}
\begin{split}
u_{\tau}&=u_{\tau}^{FF}(\overline{q},w_{c},\dot{w}_{c})   + u_{\tau}^{FB}(\overline{q},\overline{w},\overline{h})\\
u_{\tau}^{FF}(\overline{q},w_{c},\dot{w}_{c})   &=  J\pazocal{R}(\overline{q})^{T}\dot{w}_{c}   - S(J\overline{w}_{c}) \overline{w}_{c}\\
u_{\tau}^{FB}(\overline{q},\overline{w},\overline{h})   &=  -k_{p}\overline{h}\overline{\epsilon}  -k_{d}\overline{w}
\end{split}
\end{equation}
In the previous formula $k_{p}$ and $k_{d}$ are positive gains and $\overline{h} = \{-1,1\}$ is obtained by the hybrid function $\pazocal{H}_{c}$
\begin{equation}
\begin{split}
\pazocal{H}_{c} &= \begin{cases} \dot{\overline{h}} = 0  & \overline{h}\overline{\eta} \geq -\delta \\ \overline{h}^{+} \in \overline{sgn}(\overline{\eta}) & \overline{h}\overline{\eta} \leq -\delta  \end{cases}\\
\overline{sgn}(s) &= \begin{cases} sgn(s)  & \lvert s \rvert > 0 \\ \{-1,1\} &  s=0 \end{cases}\\
\end{split}
\end{equation}
$\eta \in (0,1)$ is the hysteresis threshold.\\

The control problem is more extensively explained in \autocite{marconi}, however the article does not specify how to compute the reference attitude $R_{R}$; this problem is addressed in the following section.

\section{Attitude set-point generation} \label{se:attSP}
The attitude reference orientation should be computed satisfying constraint \ref{eq:const}. The problem has just 1 degree of freedom which, for standard uses cases (i.e. for non acrobatic maneuver), is the vehicle yaw angle.\\
This thesis proposes an algorithm to compute the reference rotation matrix $R_{R}$ based on geometric projection. Considering the $yaw$ angle given, then the heading vector is defined as:
\begin{equation}
\begin{split}
d(yaw) &= [\cos{(yaw)} , \sin{(yaw)} , 0]^{T}
\end{split}
\end{equation}
The matrix $R_{R}$ is computed column-by-column as follows:
\begin{equation}
\begin{split}
R_{R}e_{3} :&= \frac{g e_{3} - \ddot{p}}{\lVert g e_{3} - \ddot{p} \rVert}\\
R_{R}e_{2} :&= \frac{R_{R}e_{3} \times d(yaw)}{\lVert R_{R}e_{3} \times d(yaw)  \rVert}\\
R_{R}e_{1} :&= \frac{R_{R}e_{2} \times R_{R}e_{3}}{\lVert R_{R}e_{2} \times R_{R}e_{3} \rVert}
\end{split}
\end{equation}
This technique allows to easily compute the reference rotation matrix that can be then easily converted to the quaternion rotation thanks to the Rodriguez formula.
The control attitude required in \autoref{eq:qerr} is then computed as follows:
\begin{equation}
\begin{split}
R_{c}e_{3} :&= \frac{v_{c} }{\lVert v_{c}  \rVert} \\
R_{c}e_{1} :&= \frac{R_{R}e_{1} \times R_{c}e_{3}}{\lVert R_{R}e_{1} \times R_{c}e_{3} \rVert}  \\
R_{c}e_{2} :&= \frac{R_{c}e_{3} \times R_{c}e_{1}}{\lVert R_{c}e_{3} \times R_{c}e_{1} \rVert}
\end{split}
\end{equation}
end finally
\begin{equation}
\begin{split}
q_{c} &= \pazocal{R}^{-1}(R_{c})
\end{split}
\end{equation}


\chapter{Multiscale Entropy as a Measure of Relevant Information in an Image}

Since the multiscale entropy extracts the information from the signal only,
it was a  challenge to see if the  astronomical content of  an image
was related to its multiscale entropy.

For this purpose, we studied the astronomical content of 200 images
of 1024 $\times$
1024 pixels extracted from scans of 8 different plates carried out
by the MAMA facility (Paris, France)
\cite{astro:guibert92} and stored at CDS (Strasbourg, France)
in the Aladin
archive \cite{compress:bonnarel99}. We estimated the content of these images
in three different ways:
\begin{enumerate}
\item By counting the number of objects in an astronomical catalog
(USNO A2.0 catalog)
within the image. The
 USNO (United States Naval Observatory)
catalog was obtained by source extraction from the same survey
 plates as we used in our study.
\item By counting the number of objects estimated in the image by the
 Sextractor object detection
package \cite{astro:bertin96}. As in the case of USNO
these detections are mainly point sources (stars, as opposed to
spatially extended objects like galaxies).
\item  By counting the number of structures detected at several scales using
 the MR/1 multiresolution analysis package \cite{starck:mr1_99}.
\end{enumerate}

\begin{figure}[htb]
\centerline{
\vbox{
\psfig{figure=fig_cds_pmm_entropy.ps,bbllx=2.8cm,bblly=2.8cm,bburx=20.5cm,bbury=15.4cm,width=10cm,height=6cm,clip=}
\psfig{figure=fig_cds_sext_entropy.ps,bbllx=2.8cm,bblly=2.8cm,bburx=20.5cm,bbury=15.4cm,width=10cm,height=6cm,clip=}
\psfig{figure=fig_cds_support_entropie.ps,bbllx=2.8cm,bblly=2.8cm,bburx=20.5cm,bbury=15.4cm,width=10cm,height=6cm,clip=}
}}
\caption{Multiscale entropy versus the number of objects: the number
of objects is, respectively, obtained from (top) the USNO catalog, (middle)
the Sextractor package, and (bottom) the MR/1 package.}
\label{fig_cds_entropy}
\end{figure}

Figs.~\ref{fig_cds_entropy} show the results of plotting these numbers
for each image against the multiscale signal entropy of the image.
The best results are obtained using the MR/1 package,
 followed by Sextractor and then by the number of sources extracted
 from USNO. Of course the latter two basically miss the content
at large scales, which is taken into account by MR/1.

Sextractor and multiresolution methods were also applied to a set of CCD
images from CFH UH8K, 2MASS and DENIS near infrared surveys.
Results obtained were very similar to what was obtained above.  This seems
to point to multiscale entropy as being a universal measurement of image
content.

Subsequently we looked for the relation between the multiscale entropy and
the optimal compression
rate of an image which we can obtain by multiresolution
techniques \cite{starck:book98}.
 By optimal compression rate we mean
a compression rate which allows all the sources to be preserved, and which
does not
degrade the astrometry and photometry.
Louys et al.\ \cite{starck:louys99}  and Couvidat \cite{compress:couvidat99}
have  estimated   this optimal
compression rate using the compression program of the
MR/1 package  \cite{starck:mr1_99}.

\begin{figure}[htb]
\centerline{
\hbox{
\psfig{figure=fig_cds_taux.ps,bbllx=2.8cm,bblly=2.8cm,bburx=20.5cm,bbury=15.4cm,width=10cm,height=6cm,clip=}
}}
\caption{Multiscale entropy of astronomical images versus the optimal
compression ratio. Images which contain a high number of sources have
a small ratio and a high multiscale entropy value. The relation
is almost linear.}
\label{fig_cds_taux}
\end{figure}

Fig.~\ref{fig_cds_taux} shows the relation obtained
between the multiscale entropy and the optimal compression rate
for all the images used in our previous tests including CCD ones.
The power law  relation is obvious thus allowing us to conclude that:
\begin{itemize}
\item  The compression rate depends strongly on the astronomical content
of the image. We can then say that compressibility is
also an estimator of the content of the image.
\item The multiscale entropy allows us to predict the optimal
compression rate of the image.
\end{itemize}


% ------------------------------------------------------------------------
% bjourdoc.tex for birkjour.cls*******************************************
% ------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass{birkjour}
%
%
% THEOREM Environments (Examples)-----------------------------------------
%
 \newtheorem{thm}{Theorem}[section]
% \newtheorem{cor}[thm]{Corollary}
% \newtheorem{lem}[thm]{Lemma}
% \newtheorem{prop}[thm]{Proposition}
% \theoremstyle{definition}
 \newtheorem{defn}[thm]{Definition}
% \theoremstyle{remark}
% \newtheorem{rem}[thm]{Remark}
% \newtheorem*{ex}{Example}
 \numberwithin{equation}{section}

\usepackage[noadjust]{cite}
\usepackage{amsfonts}
\usepackage{listings}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{booktabs}
\usepackage{float}
\usepackage{caption}

\begin{document}

%-------------------------------------------------------------------------
% editorial commands: to be inserted by the editorial office
%
%\firstpage{1} \volume{228} \Copyrightyear{2004} \DOI{003-0001}
%
%
%\seriesextra{Just an add-on}
%\seriesextraline{This is the Concrete Title of this Book\br H.E. R and S.T.C. W, Eds.}
%
% for journals:
%
%\firstpage{1}
%\issuenumber{1}
%\Volumeandyear{1 (2004)}
%\Copyrightyear{2004}
%\DOI{003-xxxx-y}
%\Signet
%\commby{inhouse}
%\submitted{March 14, 2003}
%\received{March 16, 2000}
%\revised{June 1, 2000}
%\accepted{July 22, 2000}
%
%
%
%---------------------------------------------------------------------------
%Insert here the title, affiliations and abstract:
%

\title[Linear-Time Estimation of Smooth Rotations in ARAP Deformation]
 {Linear-Time \\Estimation of Smooth Rotations in \\ARAP Surface Deformation}

%----------Author 1
\author[Mauricio Cele Lopez Belon]{Mauricio Cele Lopez Belon}
\address{Madrid, Spain}
\email{mclopez@outlook.com}

%----------classification, keywords, date
\subjclass{Parallel algorithms 68W10; Clifford algebras, spinors 15A66}

\keywords{Geometric Algebra, Quaternion Estimation, Mesh Deformation}

\date{October 21, 2019}
%----------additions
%\dedicatory{To my wife}
%%% ----------------------------------------------------------------------

\begin{abstract}

In recent years the As-Rigid-As-Possible with Smooth Rotations (SR-ARAP \cite{Levi2015}) technique has gained popularity in applications where an isommetric-type of surface mapping is needed. The advantage of SR-ARAP is that quality of deformation results is comparable to more costly volumetric techniques operating on tetrahedral meshes. The SR-ARAP relies on local/global optimization approach to minimize the non-linear least squares energy. The power of this technique resides on the local step. The local step estimates the local rotation of a small surface region, or cell, with respect of its neighboring cells, so a local change in one cell's rotation affect the neighboring cell's rotations and viceversa. The main drawback of this technique is that the local step requires a global convergence of rotation changes. Currently the local step is solved in an iterative fashion, where the number of iterations needed to reach convergence can be prohibitively large and so, in practice, only a fixed number of iterations is possible. This trade-off is, in some sense, defeating the goal of SR-ARAP. We propose a linear-time closed-form solution for estimating the codependent rotations of the local step by solving a sparse linear system of equations. Our method is more efficient than state-of-the-art since no iterations are needed and optimized sparse linear solvers can be leveraged to solve this step in linear time. It is also more accurate since this is a closed-form solution. We apply our method to generate interactive surface deformation, we also show how a multirresolution optimization can be applied to achieve real-time animation of large surfaces.

\end{abstract}

%%% ----------------------------------------------------------------------
\maketitle
%%% ----------------------------------------------------------------------
%\tableofcontents
\section{Introduction}

\indent Quatily of surface deformation aims to preserve local properties of shapes as much as possible, removing distortion in the form of shear and stretch. As-Rigid-As-Possible with Smooth Rotations (SR-ARAP) \cite{Levi2015} aims to create a surface mapping that minimize the deviation from rigid behavior on the local scale. It also makes rigid transformations smoothly vary on local neighborhoods distributing the distortions  uniformly over the surface. The resulting deformations not only preserves the shape at small scale but also at large scale significantly increasing the quality of the final result.

There are two main disadvangates on the current SR-ARAP method. First is the local step, which looks for best rotations of corresponding surface cells while keeping neighbor rotations similar to each other. It needs to reach global convergence for the whole mesh. Currently the local step is solved with a relaxation method i.e., optimizing rotations for individual cells keeping cell's neighbor rotations fixed and also optimizing neighbor rotations in the same manner repeating that process until convergence. Although the cost per relaxation iteration can be reduced considerably by avoiding SVD calculations (\cite{Ligare2020}) usually a fixed number of iterations is used in order to bound the solver time. That compromises the quality of results since a fixed number of iterations (usually two or three) is not enough to reach optimal rotations across the surface. Second is the high computational cost, that increases drastically when the number of vertices grows. The SR-ARAP is a non-linear technique that requires several iterations of local/global optmimization to converge.

In this paper we address both drawbacks of SR-ARAP, first we propose a method to solve the local step as a single linear system of equations, avoiding the need of iteratively solve a series of SVD problems which are codependant to each other. Second we propose a simple multiresolution method based on solving the non-linear system on a simplified surface mesh first and then use harmonic interpolation of rotations to transfer the optimized rotations to the full resolution mesh, leveraging the Laplacian matrix needed to solve the global step of the optimization.

\section{Related Work}

Since the focus of this paper is on As-Rigid-As-Possible (ARAP) surface deformation methods we will only review previous works on ARAP deformation. The ARAP Surface Modeling was introduced by Sorkine and Alexa \cite{Sorkine2007} to produce robust and physically plausible deformation by minimizing the local rigid transformation of the laplacian coordinates associated to every vertex. Although results on low resolution meshes looks close to physical deformations the method fails to achieve satisfactory results  on high resolution meshes. The reason is that the ARAP energy is minimized by preserving rigidity on large parts of the mesh at the expense of concentrating all the distortion on small parts of the mesh. This problem has been solved in the Smooth Rotation enhanced ARAP method (SR-ARAP) of Levi and Gotsman \cite{Levi2015} where the deformation energy is extended with a further factor that penalizes too different rotations of close vertices, significantly increasing the quality of the final result. Chao \emph{et al} \cite{Chao2010} derives the ARAP enegry from the elastic energy of continuum mechanics showing a consistent discretization for volumetric ARAP with tetrahedron cells and for 2D ARAP with triangle cells in 2D. However the ARAP energy doesn't have a consistent discretization for triangle surfaces in 3D. The SR-ARAP method  \cite{Levi2015} also address this issue providing an energy with a consistent discretization for surfaces in 3D. Further enhancements have been proposed to the SR-ARAP deformation technique addressing performance issues on large meshes \cite{Morsucci2018, Ligare2020}, making it able to adjust physical stiffness \cite{Chen2017, LeVaou2020} and Introducing local scaling to the rotation i.e., turning rigid transforms into a similarity transforms \cite{Jiang2017}.

\section{As-Rigid-As-Possible Shape Deformation with Smooth Rotations}

Given two meshes $Q$ and $P$ consisting of vertices $q_i$ and $p_i$ respectively, and directed edges $p_{ij} = p_j - p_i$ and $q_{ij} = q_j - q_i$ , the discrete As-Rigid-As-Possible with Smooth Rotations (SR-ARAP) energy is defined as:
\begin{equation}
E(Q, P) = \sum_{i=1}^m { (\sum_{j \in N(i)} { c_{ij} \|R_i (q_j - q_i) \tilde R_i - (p_j - p_i)  \|^2 } \nonumber \\
+ \alpha A \sum_{j \in N(i)} {w_{ij} \| R_j - R_i \|^2} )}\nonumber
\end{equation}
where $R_1, ..., R_m \in \mathbb{H}$ are local quaternions, $N(i)$ denote the set of $1$-ring neighbors of vertex at position $i$, $c_{ij}$ are weighting coefficients such that $\sum_j^n{c_{ij}} = 1$, typically the familiar cotangent weights, $w_{ij}$ are positive weighting coefficients such that $\sum_j^n{w_{ij}} = 1$, $A$ is the mesh area used to make the energy scale invariant and $\alpha$ is a positive scalar parameter.

The main idea of this method is breaking the surface into overlapping cells and seek for keeping the cells transformations as rigid as possible in the least squares sense. Overlap of the cells is necessary to avoid surface stretching or shearing at the boundary of the cells.
The first term is a membrane energy which penalizes stretching and shearing of a cell and the second term is the bending energy which penalizes the difference between a cell's rotation and the rotations of its neighboring cells.
The objective of the membrane term is to lower the distortion of a cell by keeping the map differential close to rigid.
The objective of the bending term is to keep the variation in the rotations in a cell neighborhood low, such that the neighborhood would transform as a unit, as much as possible.

The vertices of mesh $Q$ are in original position while vertices of mesh $P$ are the deformed vertices and the quaternion $R_i$ is the best rigid transformation, in the least squares sense, relating the original and the deformed vertices.
This is a non-linear optimization problem that is tipically solved by a iterative local/global method that solves two linear sub-problems on each iteration.

The first step, so called local step, is to consider the vertices of $P$ constant and obtain the best rigid transformation $R_i$ for each cell. The second step, so called global step, is to consider the rotations $R_i$ constant and computing the optimal deformed vertices $p_i$ in the least squares sense.

\section{Global Step}

The global step is computing the optimal vertices $\{p_i\} \in P$.
\begin{eqnarray*}
E(P) = \min_{p_1,...,p_m \in \mathbb R^3} \sum_{i=1}^m  (  \sum_{j \in N(i)} { c_{ij} \|R_i q_{ij} \tilde R_i -  p_{ij}\|^2 } \\
+ \alpha A \sum_{j \in N(i)} { w_{ij} \|R_i - R_j\|^2 } )
\end{eqnarray*}
Taking the partial derivatives of $E(P)$ w.r.t. $p_i$ and equating the result to zero lead us to obtain the linear system of Equation~(\ref{eq:ls_for_p_ga}) (\cite{Lopez2013}):
\begin{eqnarray}
\label{eq:ls_for_p_ga}
\sum_{j \in N(i)} { c_{ij} (p_j - p_i) } = \sum_{j \in N(i)} { \frac{c_{ij}}{2} (R_i q_{ij} \tilde  R_i + R_j q_{ij} \tilde R_j) }
\end{eqnarray}
which can be expressed in matrix form as $\mathrm L \; \mathrm P = \mathrm C$, where $\mathrm L$ is the discrete Laplace-Beltrami operator, $\mathrm P$ is the column of target positions and $\mathrm C$ a column vector whose $i$th row is the right hand side of equation (\ref{eq:ls_for_p_ga}). Constraints of the form $p_i = p^{const}_i$ are incorporated into the system by substituting the corresponding variables i.e., erasing respective rows and columns from $\mathrm L$ and updating the right-hand side of equation (\ref{eq:ls_for_p_ga}) with the values $p^{const}_i$. The system is then solved in the least squares sense:
\begin{eqnarray}
(\mathrm L^T \mathrm L) \; \mathrm P = \mathrm L^T \ \mathrm C
\end{eqnarray}

\section{Local Step}

As described in a previous sections, the rotations matching cell's are codependent to each other over the whole mesh. The current approach is to optimize the rotations with a relaxation method in which the rotation of each cell is independently computed, while keeping the neighbor rotations fixed, repeating it until global convergence is reached. At least two relaxation iterations must be done per each global iteration. In this section we show how the local step can be solved in closed form as a single sparse linear system eliminating entirely the need of relaxation iterations.

\subsection{Closed Form of Local Step}

We attempt to minimize the SR-ARAP energy function:
\begin{eqnarray}
E(R) = \min_{R_1,...,R_m \in \mathbb H} \sum_{i=1}^m  (  \sum_{j \in N(i)} { c_{ij} \|R_i q_{ij} \tilde R_i -  p_{ij}\|^2 } \\
+ \alpha A \sum_{j \in N(i)} { w_{ij} \|R_i - R_j\|^2 } )
\end{eqnarray}

Ignoring temporarily the sum over all vertices, the energy to minimize in the neighborhood of a point $p_i$ is $E_i(R_i)$:

\begin{eqnarray}
E_i(R_i) =  \sum_{j \in N(i)} { c_{ij} \|R_i q_{ij} \tilde R_i - p_{ij}  \|^2 } + \alpha A \sum_{j \in N(i)} {w_{ij} \| R_j - R_i \|^2} \nonumber
\end{eqnarray}
Notice that the first term $\sum_{j \in N(i)} { c_{ij} \|R_i q_{ij} \tilde R_i - p_{ij}  \|^2 } $ can be written in matrix language as the quadratic form $R_i^T M_i R_i$ where $M_i$ is a $4\times4$ matrix constructed from vectors $q_{ij}$ and $p_{ji}$ (see Section \ref{section:the_form_of_arap_matrix}):
\begin{eqnarray}
		E_i(R_i) = R_i^T M_i R_i + \alpha A \sum_{j \in N(i)} {w_{ij} \| R_j - R_i \|^2  }\\ \nonumber
\end{eqnarray}

Differentiating with respect to $R_i$ we get:
\begin{eqnarray}
	\label{eqn:max_energy}
	\frac{\partial E_i(R_i)}{\partial R_i}  = 2 M_i R_i + 2 \alpha A \sum_{j \in N(i)} {w_{ij} (R_i - R_j) }\\
	= M_i R_i + \alpha A R_i - \alpha A \sum_{j \in N(i)} {w_{ij} R_j }
\end{eqnarray}

Setting the partial derivatives to zero $\frac{\partial E_i(R_i)}{\partial R_i}  = 0$

\begin{eqnarray}
	\label{eqn:local_solution}
	(M_i + \alpha A I)R_i  = \alpha A \sum_{j \in N(i)} {w_{ij} R_j }\\ \nonumber
\end{eqnarray}

Which is a linear system of equations. The system (\ref{eqn:local_solution}) can be solved for all quaternions in closed form. Writing (\ref{eqn:local_solution}) in matrix form we get:

\begin{eqnarray}
	\label{eqn:local_solution_closed_form}
	\mathrm M \; \mathrm R = \mathrm W \; \mathrm R\\
	(\mathrm M - \mathrm W) \mathrm R = \mathrm 0
\end{eqnarray}

Where $\mathrm M$ is a symmetric sparse  matrix  with dimensions $4n\times 4n$ which is stacking $M_i$ at its diagonal, $\mathrm W$ is a discrete Laplacian matrix with dimensions $4n\times 4n$ derived from RHS of (\ref{eqn:local_solution}) i.e., $\sum_{j \in N(i)} {\alpha A w_{ij} R_j }$ holding the coefficients $\alpha A w_{ij}$. $\mathrm R$ is column matrix of dimensions $1\times 4n$ stacking the coefficients of quaternions $R_i$.

The sparse linear system of (\ref{eqn:local_solution_closed_form}) can be solved by imposing quaternion constraints $R^{const}_i$ which corresponds to best rotation of constrained points $p^{const}_i$:
\begin{eqnarray}
	\label{eqn:local_solution_closed_form_const}
	(\mathrm M - \mathrm W) \mathrm R = \mathrm 0\\
	s.t. \ R_i = R^{const}_i \nonumber
\end{eqnarray}

Constraints of the form $R_i = R^{const}_i$ are incorporated into the system by substituting the corresponding variables i.e., erasing respective rows and columns from $(\mathrm M - \mathrm W)$ and updating the right-hand side of (\ref{eqn:local_solution_closed_form_const}) with the values $R^{const}_i$. The system is then solved in the least squares sense.

Since the constraint $R_i^T R_i = 1$ is not honored by the linear system the quaternion $R_i$ given as solution must be normalized. As shown in \cite{Ligare2020} the solution of (\ref{eqn:local_solution}) gives a linear approximate solution to the optimal quaternion in the least squares sense. Our results confirm that the proposed linearization is accurate for the SR-ARAP rotations and it is not affecting accuracy in any significant way.

\subsection{Rotation constraints $R^{const}_i$}

The rotation constraints $R^{const}_i$ in (\ref{eqn:local_solution_closed_form_const}) have to be computed directly from equation (\ref{eqn:local_solution}) for each constrained point $p^{const}_i$:
\begin{equation}
	R^{const}_i  = (M_i + \alpha A I)^{-1}  \sum_{j \in N(i)} {\alpha A w_{ij} R^{prev}_j } \nonumber
\end{equation}
where neighbor rotations $R^{prev}_j$ are known from previous iteration. So computing constraint quaternionss amounts to solve a small $4\times4$ linear system. The resulting quaternion $R^{const}_i$ must be normalized.

 \subsection{Rotation's Feedback}

The linear system of (\ref{eqn:local_solution_closed_form_const}) find quaternions from scratch i.e., it doesn't take into account the previous state of the quaternions i.e., the temporal coherence. That might lead to undesired results in an animation sequence. In particular, the sense of the rotations found by (\ref{eqn:local_solution_closed_form_const}) for some animation step are not always respecting the sense of rotations from previous time. The abrupt change in the sense of rotation cause animation artifacts specially for large rotations.

The equation (\ref{eqn:local_solution_closed_form_const}) allow us to introduce \emph{feedback} quaternions to the RHS which acts as \emph{hints} to find quaternions close to the ones in previous iteration. Given the quaternion $R^{prev}_i$ and a positive small scalar value $\epsilon_i$ we augment equation (\ref{eqn:local_solution}) in the following way:

\begin{eqnarray}
	\label{eqn:local_solution_feedback}
	(M_i + \alpha A I)R_i  = \alpha A \sum_{j \in N(i)} {w_{ij} R_j} + \epsilon R^{prev}_i
\end{eqnarray}
where  $\sum_{j \in N(i)} {w_{ij}} = 1-\epsilon$. Our intention is to make $R_i$ a neighbor of itself, in some sense. The strength of feedback is given by $\epsilon$. So the global system is changed as follows:
\begin{eqnarray}	\label{eqn:local_solution_closed_form_const_feedback}
	(\mathrm M - \mathrm W) \mathrm R = \epsilon \mathrm R^{prev}\\
	s.t. \ R_i = R^{const}_i \nonumber
\end{eqnarray}
where $\mathrm R^{prev}$ is a $1\times4n$ column vector stacking all the unconstrained quaternions $R^{prev}_i$ from previous iteration.

\section{Multiresolution Optimization}

For achieving real-time performance we optimize the SR-ARAP energy in a low resolution version of the input mesh and then we transfer that solution to the full resolution mesh. To obtain the low resolution mesh we simplify the mesh using \emph{half edge collapses} (i.e., the simplified mesh is a triangulation of a subset of the original vertices) while minimizing the Quadrics error metric.
After we obtained the optimal deformed shape on the simplified mesh we transfer the optimized rotations to the full resolution mesh using Harmonic Interpolation of quaternions (see Section \ref{section:harmonic_interpolation_rotors}) and then solve the following linear system using the optimized vertices of the low resolution mesh as positional constraints:
\begin{eqnarray*}
\sum_{j \in N(i)} { c_{ij} (p_j - p_i) } = \sum_{j \in N(i)} { \frac{c_{ij}}{2} (R_i q_{ij} \tilde  R_i + R_j q_{ij} \tilde R_j) }
\end{eqnarray*}

\subsection{Harmonic Interpolation of Quaternions}
\label{section:harmonic_interpolation_rotors}

The seminal work of Pinkall and Polthier \cite{Pinkall1993} shows how to interpolate given data over a discrete domain using harmonic maps. Harmonic maps are critical points of the Dirichlet energy (stretching energy) $\int_{\Omega}{ |\nabla f|^2 dA }$, which generates minimal surfaces.
The \emph{discrete harmonic energy} of a map $f$ defined on mesh vertices $\{p_i\}$ has the form:
\begin{equation}
E(f) = \sum_{i,j}{c_{ij} \| f(p_j) - f(p_i) \|^2 }
\end{equation}
where $w_{ij}$ are the (symmetric) cotangent weights \cite{Pinkall1993} defined on triangle edges going from $p_i$ to $p_j$. The discrete Laplacian operator can be identified in that energy as:
\begin{equation}
\Delta f = \sum_{j \in N_i} { c_{ij} ( f(p_j) - f(p_i) ) }
\end{equation}
where $N_i$ is the set of indices of the neighbors of vertex $p_i$. It is known that harmonic energy minimizes angular distortions. That means that harmonic functions smoothly blend boundary conditions over the domain. Harmonic functions are intrinsic to surfaces and independent of the discretization used to produce meshes. In spirit similar to \cite{Zayer2005}, we propose the interpolation of quaternions over a mesh using harmonic functions. The harmonic quaternion interpolation over a surface mesh can be formulated as the solution to the following discrete harmonic equation:
\begin{eqnarray}
\label{eq:harmonic_rotor}
   \sum_{j \in N(i)} { c_{ij} ( R_j - R_i ) } = 0
\end{eqnarray}
subject to Dirichlet boundary conditions $R_k = R^{const}_k$, where $\{R^{const}_k\}$ are the optimized quaternions from the lower resolution mesh and $\{c_{ij}\}$ are the cotangent weights. This leads to the solution of a sparse linear matrix system. This interpolation produces a smooth field of quaternions by ``averaging'' the boundary conditions gradually over the surface. This is in effect equivalent to a linear interpolation of boundary conditions across the surface. It can be written in matrix form as:
\begin{eqnarray}
	\mathrm L \; \mathrm R = 0\\
	s.t. \ R_k = R^{const}_k \nonumber
\end{eqnarray}
where $\mathrm L$ is discrete Laplacian operator used to solve the global step. Note that interpolated quaternons are not of unit length and must be normalized afterwards. Despite the simplicity of this approach, it works surprisingly well, it is extremely efficient, and it provides a natural propagation at no extra cost.

 \section{The form of $M_i$}
 \label{section:the_form_of_arap_matrix}

Notice that the membrane term $\sum_j \|R_i q_{ij} \tilde R_i - p_{ij} \|^2$ is equivalent to $\sum_j  \|R_i q_{ij} - p_{ij} R_i\|^2$ under the L2 norm. Also notice that  $R_i q_{ij} - p_{ij} R_i$ can be rewriten as $(w_i + B_i) q_{ij}  - p_{ij} (w_i + B_i)$ for some a scalar $w_i$ and pure quaternion $B_i$ such that $R_i = w_i + B_i$. Expanding the quaternion product in terms of the inner product and the cross product we get:
\begin{eqnarray}
     (q_{ij} - p_{ij}) w_i - (q_{ij} - p_{ij}) \cdot B_i - (q_{ij} + p_{ij}) \times B_i
\end{eqnarray}
The expression above can be written in matrix form to get the matrix system $M_{ij} R_i$:
\begin{eqnarray}
	M_{ij} R_i =
	\left[\begin{array}{cc}
		0        &       -d_{ij}^T \\
		d_{ij}  &   \left[ s_{ij} \right]^T_\times \\
	\end{array}\right]
	\left[\begin{array}{c}
		w_i \\
		B_i
	\end{array}\right] =
	\left[\begin{array}{c}
		-d_{ij}^T B_i \\
		w_i d_{ij} - s_{ij} \times B_i
	\end{array}\right]\\
	d_{ij} = q_{ij} - p_{ij} \ \ s_{ij} = p_{ij} + q_{ij}  \nonumber
\end{eqnarray}
where $d_{ij}$ and $s_{ij}$ are $3 \times 1$ column vectors holding pure quaternion coefficients, $M_{ij}$ is a skew-symmetric $4\times 4$ real matrix, so that $M_{ij}^T = -M_{ij}$. The quaternion $R_i$ is represented as $4 \times 1$ column vector made of the scalar $w_i$ and the $3 \times 1$ column vector $B_i$ holding the pure quaternion components. The $3\times 3$ matrix $\left[ s_{ij} \right]_\times$ is representing the skew-symmetric cross-product matrix as usually defined for vectors in $\mathbb R^3$.

We can express $\sum_j \|R_i q_{ij} - p_{ji} R_i\|^2$ as the quadratic form $R_i^T M_i R_i$ where $M_i = \sum_j^n { c_{ij} M_{ij}^T M_{ij}}$. Note that since $M_{ij}$ is skew-symmetric, the product $M_{ij}^T M_{ij}$ is symmetric and positive semi-definite.
Consequently the matrix $M_i$ is also symmetric positive semi-definite. It follows that all eigenvalues of $M_i$ are real and $\lambda_i \geq 0$.
\begin{eqnarray}
	M_{ij}^T M_{ij} =
	\left[\begin{array}{cc}
		\| d_{ij} \|^2       &         (s_{ij} \times d_{ij})^T \\
		s_{ij} \times d_{ij}  &    d_{ij} d_{ij}^T - \left[ s_{ij} \right]^2_\times \\
	\end{array}\right]\\
	d_{ij} = q_{ij} - p_{ij} \ \ s_{ij} = p_{ij} + q_{ij}  \nonumber
\end{eqnarray}

 \subsection{Efficient Computation of $M_i$}

The symmetric matrix $M_{ij}^T M_{ij}$ has a simple form:

\begin{eqnarray*}
	M_{ij}^T M_{ij} =
	\left[\begin{array}{cc}
		\| d_{ij} \|^2        &         (s_{ij} \times d_{ij})^T \\
		s_{ij} \times d_{ij}  &    d_{ij} d_{ij}^T - s_{ij} s_{ij}^T + \| s_{ij} \|^2 I_{3\times3} \\
	\end{array}\right]\\
     d_{ij} = q_{ij} - p_{ij} \ \ s_{ij} = p_{ij} + q_{ij}  \nonumber
\end{eqnarray*}

Writing it in terms of $p_{ij}$ and $q_{ij}$ we get:

\begin{eqnarray}
   \label{eqn:matrix_fast}
   	M_{ij}^T M_{ij}
   	= 2
	\left[\begin{array}{cc}
		q_{ij}^T p_{ij}       &         (q_{ij} \times p_{ij})^T \\
		q_{ij} \times p_{ij}  &    q_{ij} p_{ij}^T + p_{ij} q_{ij}^T - q_{ij}^T p_{ij} I_{3\times3} \\
	\end{array}\right]\\ \nonumber
    + (\| p_{ij} \|^2 + \| q_{ij} \|^2) I_{4\times4}
\end{eqnarray}
All terms of \ref{eqn:matrix_fast} can be derived from the dyadic tensor $q_{ij} p_{ij}^T$ plus the quantity $\|p_{ij} \|^2 + \| q_{ij} \|^2$. Since matrix $q_{ij} p_{ij}^T$ is of $3\times3$ its computation is efficient.

\section{Implementation}

The author's source code is publicly available at github \cite{GALinearizedArap}.

\section{Results}

\section{Conclusion}

\bibliographystyle{abbrv}
\bibliography{linealizedrotations}

% ------------------------------------------------------------------------
\end{document}
% ------------------------------------------------------------------------