MeshLib
 
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{
8
10template <typename T>
12{
13public:
15 void addPoint( T x, T y );
16
18 void addPoint( T x, T y, T weight );
19
21 Parabola<T> getBestParabola( T tol = std::numeric_limits<T>::epsilon() ) const;
22
23private:
25 Vector3<T> b_;
26};
27
28template <typename T>
30{
31 const Vector3<T> v{ x*x, x, T(1) };
32 m_ += outerSquare( v );
33 b_ += y * v;
34}
35
36template <typename T>
37void BestFitParabola<T>::addPoint( T x, T y, T weight )
38{
39 const Vector3<T> v{ x*x, x, T(1) };
40 m_ += outerSquare( weight, v );
41 b_ += weight * y * v;
42}
43
44template <typename T>
46{
47 auto res = m_.pseudoinverse( tol ) * b_;
48 return { res[0], res[1], res[2] };
49}
50
51} //namespace MR
accumulates a number of (x,y) points to find the best-least-squares parabola approximating them
Definition MRBestFitParabola.h:12
Parabola< T > getBestParabola(T tol=std::numeric_limits< T >::epsilon()) const
computes the best approximating parabola from the accumulated points;
Definition MRBestFitParabola.h:45
void addPoint(T x, T y)
accumulates one more point for parabola fitting
Definition MRBestFitParabola.h:29
Definition MRCameraOrientationPlugin.h:7
Represents quadratic function f(x) = a*x*x + b*x + c.
Definition MRParabola.h:11
Definition MRSymMatrix3.h:15
Definition MRMesh/MRVector3.h:19