40 lines
1.7 KiB
TeX
40 lines
1.7 KiB
TeX
|
The splines are a necessary element for everything that will follow. This is
|
||
|
why we tried to make it as generic as possible. For this, we used a C++11
|
||
|
feature called \emph{variadic templates}. A spline is composed of control
|
||
|
points (represented as C++ tuples), a nodes vector and degree. The class we
|
||
|
made looks like this
|
||
|
|
||
|
\begin{lstlisting}[language=c++]
|
||
|
template<typename... Types>
|
||
|
class Spline
|
||
|
{
|
||
|
public:
|
||
|
std::tuple<Types...> operator()(float t);
|
||
|
std::tuple<Types...> prime(float t);
|
||
|
|
||
|
private:
|
||
|
std::vector<std::tuple<Types...>> controlPoints;
|
||
|
std::vector<float> nodes;
|
||
|
int degree;
|
||
|
};
|
||
|
\end{lstlisting}
|
||
|
|
||
|
We redefined the \texttt{operator()} to be able to \emph{evaluate} a spline at
|
||
|
a certain time, and the result will be an object which is a barycenter of those
|
||
|
control points. We also made a member function \texttt{prime} to be able to
|
||
|
compute the derivative of a spline.
|
||
|
|
||
|
The \texttt{operator()} computes the barycent of the control points like this
|
||
|
$$C(t) = \sum_{i=0}^m P_i N_i^n(t)$$
|
||
|
where $(P_i)_{i\in [[0,m]]}$ are the $m+1$ control points, $n$ is the degree of
|
||
|
the spline and
|
||
|
$$N_i^0(t) = \left\{\begin{matrix}1&\text{if } t \in [t_i, t_{i+1}] \\ 0 & \text{otherwise} \end{matrix} \right.$$
|
||
|
$$ N_i^k(t) = \frac{t-t_i}{t_{i+k}-t_{i}} N_i^{k-1}(t) + \frac{t_{i+k+1} - t}{t_{i+k+1}-t_{i+1}} N_{i+1}^{k-1}(t) \quad\text{assuming} \quad \frac{0}{0} = 0$$
|
||
|
|
||
|
The \texttt{prime} member function computes the derivative like this
|
||
|
$$C'(t) = \sum_{i=0}^m N_i^{\prime n} (t) P_i $$
|
||
|
with
|
||
|
$$ N_i^{\prime n}(t) = \frac{n}{t_{i+n}-t_{i}}N_i^{n-1}(t) - \frac{n}{t_{i+n+1}-t_{i+1}}N_{i+1}^{n-1}(t)$$
|
||
|
|
||
|
These formulas have been taken from the reference \cite{spline}.
|