MeshLib C++ Docs
Loading...
Searching...
No Matches
MRBestFitParabola.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRParabola.h"
4#include "MRSymMatrix3.h"
5
6namespace MR
7{
10
11
13template <typename T>
15{
16public:
18 void addPoint( T x, T y );
19
21 void addPoint( T x, T y, T weight );
22
24 Parabola<T> getBestParabola( T tol = std::numeric_limits<T>::epsilon() ) const;
25
26private:
28 Vector3<T> b_;
29};
30
31template <typename T>
33{
34 const Vector3<T> v{ x*x, x, T(1) };
35 m_ += outerSquare( v );
36 b_ += y * v;
37}
38
39template <typename T>
40void BestFitParabola<T>::addPoint( T x, T y, T weight )
41{
42 const Vector3<T> v{ x*x, x, T(1) };
43 m_ += outerSquare( weight, v );
44 b_ += weight * y * v;
45}
46
47template <typename T>
49{
50 auto res = m_.pseudoinverse( tol ) * b_;
51 return { res[0], res[1], res[2] };
52}
53
54}
accumulates a number of (x,y) points to find the best-least-squares parabola approximating them
Definition MRBestFitParabola.h:15
Parabola< T > getBestParabola(T tol=std::numeric_limits< T >::epsilon()) const
computes the best approximating parabola from the accumulated points;
Definition MRBestFitParabola.h:48
void addPoint(T x, T y)
accumulates one more point for parabola fitting
Definition MRBestFitParabola.h:32
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Represents quadratic function f(x) = a*x*x + b*x + c.
Definition MRParabola.h:14
Definition MRSymMatrix3.h:18
Definition MRVector3.h:33