MeshLib Documentation
Loading...
Searching...
No Matches
MRQuadraticForm.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRSymMatrix2.h"
4#include "MRSymMatrix3.h"
5
6namespace MR
7{
8
11template <typename V>
13{
14 using T = typename V::ValueType;
15 using SM = typename V::SymMatrixType;
16
18 T c = 0;
19
21 [[nodiscard]] T eval( const V & x ) const { return dot( x, A * x ) + c; }
22
24 void addDistToOrigin( T weight ) { A += SM::diagonal( weight ); }
25
27 void addDistToPlane( const V & planeUnitNormal ) { A += outerSquare( planeUnitNormal ); }
28 void addDistToPlane( const V & planeUnitNormal, T weight ) { A += weight * outerSquare( planeUnitNormal ); }
29
31 void addDistToLine( const V & lineUnitDir ) { A += SM::identity() - outerSquare( lineUnitDir ); }
32 void addDistToLine( const V & lineUnitDir, T weight ) { A += weight * ( SM::identity() - outerSquare( lineUnitDir ) ); }
33};
34
38template <typename V>
39[[nodiscard]] MRMESH_API std::pair< QuadraticForm<V>, V > sum(
40 const QuadraticForm<V> & q0, const V & x0,
41 const QuadraticForm<V> & q1, const V & x1,
42 bool minAmong01 = false );
43
47template <typename V>
49 const QuadraticForm<V> & q0, const V & x0,
50 const QuadraticForm<V> & q1, const V & x1,
51 const V & pos );
52
53} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
Definition MRCameraOrientationPlugin.h:8
Definition MRQuadraticForm.h:13
typename V::ValueType T
Definition MRQuadraticForm.h:14
T c
Definition MRQuadraticForm.h:18
void addDistToOrigin(T weight)
adds to this squared distance to the origin point
Definition MRQuadraticForm.h:24
MRMESH_API std::pair< QuadraticForm< V >, V > sum(const QuadraticForm< V > &q0, const V &x0, const QuadraticForm< V > &q1, const V &x1, bool minAmong01=false)
if true then the minimum is selected only between points x0 and x1
void addDistToLine(const V &lineUnitDir, T weight)
Definition MRQuadraticForm.h:32
void addDistToLine(const V &lineUnitDir)
adds to this squared distance to line passing via origin with given unit direction
Definition MRQuadraticForm.h:31
SM A
Definition MRQuadraticForm.h:17
T eval(const V &x) const
evaluates the function at given x
Definition MRQuadraticForm.h:21
void addDistToPlane(const V &planeUnitNormal)
adds to this squared distance to plane passing via origin with given unit normal
Definition MRQuadraticForm.h:27
typename V::SymMatrixType SM
Definition MRQuadraticForm.h:15
MRMESH_API QuadraticForm< V > sumAt(const QuadraticForm< V > &q0, const V &x0, const QuadraticForm< V > &q1, const V &x1, const V &pos)
void addDistToPlane(const V &planeUnitNormal, T weight)
Definition MRQuadraticForm.h:28