Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpRxyzVector.cpp
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4
*
5
* This software is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
9
* See the file LICENSE.txt at the root directory of this source
10
* distribution for additional information about the GNU GPL.
11
*
12
* For using ViSP with software that can not be combined with the GNU
13
* GPL, please contact Inria about acquiring a ViSP Professional
14
* Edition License.
15
*
16
* See https://visp.inria.fr for more information.
17
*
18
* This software was developed at:
19
* Inria Rennes - Bretagne Atlantique
20
* Campus Universitaire de Beaulieu
21
* 35042 Rennes Cedex
22
* France
23
*
24
* If you have questions regarding the use of this file, please contact
25
* Inria at visp@inria.fr
26
*
27
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
*
30
* Description:
31
* Rxyz angle parameterization for the rotation.
32
* Rxyz(phi,theta,psi) = Rot(x,phi)Rot(y,theta)Rot(z,psi).
33
*/
34
40
41
#include <math.h>
42
43
#include <visp3/core/vpRxyzVector.h>
44
45
BEGIN_VISP_NAMESPACE
46
const
unsigned
int
vpRxyzVector::constr_val_3 = 3;
48
vpRxyzVector::vpRxyzVector
() :
vpRotationVector
(constr_val_3) { }
49
56
vpRxyzVector::vpRxyzVector
(
double
phi,
double
theta,
double
psi) :
vpRotationVector
(constr_val_3) {
buildFrom
(phi, theta, psi); }
57
63
vpRxyzVector::vpRxyzVector
(
const
vpRotationMatrix
&R) :
vpRotationVector
(constr_val_3) {
buildFrom
(R); }
64
71
vpRxyzVector::vpRxyzVector
(
const
vpThetaUVector
&tu) :
vpRotationVector
(constr_val_3) {
buildFrom
(tu); }
72
74
vpRxyzVector::vpRxyzVector
(
const
vpColVector
&rxyz) :
vpRotationVector
(constr_val_3) {
buildFrom
(rxyz); }
75
77
vpRxyzVector::vpRxyzVector
(
const
std::vector<double> &rxyz) :
vpRotationVector
(constr_val_3) {
buildFrom
(rxyz); }
78
85
vpRxyzVector
&
vpRxyzVector::buildFrom
(
const
vpRotationMatrix
&R)
86
{
87
double
COEF_MIN_ROT = 1e-6;
88
double
phi;
89
const
unsigned
int
index_0 = 0;
90
const
unsigned
int
index_1 = 1;
91
const
unsigned
int
index_2 = 2;
92
93
if
((fabs(R[index_1][index_2]) < COEF_MIN_ROT) && (fabs(R[index_2][index_2]) < COEF_MIN_ROT)) {
94
phi = 0;
95
}
96
else
{
97
phi = atan2(-R[index_1][index_2], R[index_2][index_2]);
98
}
99
100
double
si = sin(phi);
101
double
co = cos(phi);
102
double
theta = atan2(R[index_0][index_2], (-si * R[index_1][index_2]) + (co * R[index_2][index_2]));
103
double
psi = atan2((co * R[index_1][index_0]) + (si * R[index_2][index_0]), (co * R[index_1][index_1]) + (si * R[index_2][index_1]));
104
105
buildFrom
(phi, theta, psi);
106
107
return
*
this
;
108
}
109
115
vpRxyzVector
&
vpRxyzVector::buildFrom
(
const
vpThetaUVector
&tu)
116
{
117
vpRotationMatrix
R;
118
R.buildFrom(tu);
119
buildFrom
(R);
120
121
return
*
this
;
122
}
123
130
vpRxyzVector
&
vpRxyzVector::buildFrom
(
const
double
&phi,
const
double
&theta,
const
double
&psi)
131
{
132
const
unsigned
int
index_0 = 0;
133
const
unsigned
int
index_1 = 1;
134
const
unsigned
int
index_2 = 2;
135
data
[index_0] = phi;
136
data
[index_1] = theta;
137
data
[index_2] = psi;
138
return
*
this
;
139
}
140
144
vpRxyzVector
&
vpRxyzVector::buildFrom
(
const
vpColVector
&rxyz)
145
{
146
const
unsigned
int
val_3 = 3;
147
if
(rxyz.
size
() != val_3) {
148
throw
(
vpException
(
vpException::dimensionError
,
"Cannot construct a R-xyz vector from a %d-dimension col vector"
,
149
rxyz.
size
()));
150
}
151
for
(
unsigned
int
i = 0; i < val_3; ++i) {
152
data
[i] = rxyz[i];
153
}
154
155
return
*
this
;
156
}
157
161
vpRxyzVector
&
vpRxyzVector::buildFrom
(
const
std::vector<double> &rxyz)
162
{
163
const
unsigned
int
val_3 = 3;
164
if
(rxyz.size() != val_3) {
165
throw
(
vpException
(
vpException::dimensionError
,
"Cannot construct a R-xyz vector from a %d-dimension std::vector"
,
166
rxyz.size()));
167
}
168
for
(
unsigned
int
i = 0; i < val_3; ++i) {
169
data
[i] = rxyz[i];
170
}
171
172
return
*
this
;
173
}
174
198
vpRxyzVector
&
vpRxyzVector::operator=
(
double
v)
199
{
200
for
(
unsigned
int
i = 0; i <
dsize
; ++i) {
201
data
[i] = v;
202
}
203
204
return
*
this
;
205
}
206
233
vpRxyzVector
&
vpRxyzVector::operator=
(
const
vpColVector
&rxyz)
234
{
235
const
unsigned
int
val_3 = 3;
236
if
(rxyz.
size
() != val_3) {
237
throw
(
vpException
(
vpException::dimensionError
,
"Cannot set a R-xyz vector from a %d-dimension col vector"
,
238
rxyz.
size
()));
239
}
240
for
(
unsigned
int
i = 0; i < val_3; ++i) {
241
data
[i] = rxyz[i];
242
}
243
244
return
*
this
;
245
}
246
247
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
269
vpRxyzVector
&
vpRxyzVector::operator=
(
const
std::initializer_list<double> &list)
270
{
271
if
(list.size() >
size
()) {
272
throw
(
vpException
(
273
vpException::dimensionError
,
274
"Cannot set Euler x-y-z vector out of bounds. It has only %d values while you try to initialize with %d values"
,
275
size
(), list.size()));
276
}
277
std::copy(list.begin(), list.end(),
data
);
278
return
*
this
;
279
}
280
#endif
281
END_VISP_NAMESPACE
vpArray2D< double >::data
double * data
Definition
vpArray2D.h:149
vpArray2D< double >::dsize
unsigned int dsize
Definition
vpArray2D.h:1207
vpArray2D::size
unsigned int size() const
Return the number of elements of the 2D array.
Definition
vpArray2D.h:435
vpColVector
Implementation of column vector and the associated operations.
Definition
vpColVector.h:191
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpException::dimensionError
@ dimensionError
Bad dimension.
Definition
vpException.h:71
vpRotationMatrix
Implementation of a rotation matrix and operations on such kind of matrices.
Definition
vpRotationMatrix.h:130
vpRotationVector::vpRotationVector
vpRotationVector()
Constructor that constructs a 0-size rotation vector.
Definition
vpRotationVector.h:106
vpRxyzVector::operator=
vpRxyzVector & operator=(const vpColVector &rxyz)
Definition
vpRxyzVector.cpp:233
vpRxyzVector::buildFrom
vpRxyzVector & buildFrom(const vpRotationMatrix &R)
Definition
vpRxyzVector.cpp:85
vpRxyzVector::vpRxyzVector
vpRxyzVector()
Definition
vpRxyzVector.cpp:48
vpThetaUVector
Implementation of a rotation vector as axis-angle minimal representation.
Definition
vpThetaUVector.h:172
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
core
src
math
transformation
vpRxyzVector.cpp
Generated by
1.17.0