-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuncertain.cpp
More file actions
76 lines (58 loc) · 2.27 KB
/
uncertain.cpp
File metadata and controls
76 lines (58 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
* Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "kernel.h"
#include "matfun.h"
#include "uncertain.h"
#include <cassert>
#include <cfloat>
#include <Eigen/Core>
using Eigen::Matrix;
using Eigen::Matrix2d;
using Eigen::Vector2d;
using Matfun::null;
using Matfun::sign;
namespace Uncertain {
//! Spherically normalize the entity
void BasicEntity2D::normalizeSpherical()
{
// qDebug() << Q_FUNC_INFO;
const Matrix3d I = Matrix3d::Identity();
assert(m_val.norm() > 0.0);
const Matrix3d Jac = (I - m_val*m_val.adjoint()/m_val.squaredNorm()) / m_val.norm();
m_cov = Jac*m_cov*Jac.adjoint();
m_val.normalize(); // x = x /norm(x)
}
//! Check if uncertainty entity is identical with uncertain entity 'us'
bool BasicEntity2D::isIdenticalTo( const BasicEntity2D & us,
const double T) const
{
BasicEntity2D a(*this);
BasicEntity2D b(us); // copies
// fix ambiguities
a.normalizeSpherical();
b.normalizeSpherical();
int idx = 0; // visitor
a.v().cwiseAbs().maxCoeff( &idx ); // [~,idx] = max( abs(a) )
a.m_val *= sign( a.v(idx) ); // a = a*sign( a(idx) );
b.m_val *= sign( b.v(idx) ); // b = b*sign( b(idx) );
const Matrix<double, 3, 2> Jac = null(a.v()); // (A.120)
const Vector2d d = Jac.adjoint()*( a.v() -b.v() ); // (10.141)
const Matrix2d Sigma_dd = Jac.adjoint() * (a.Cov() + b.Cov()) * Jac;
return d.dot( Sigma_dd.ldlt().solve(d) ) < T; // dof = 2
}
} // namespace Uncertain