Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpRzyxVector.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
* Rzyx angle parameterization for the rotation.
32
* Rzyx(phi,theta,psi) = Rot(z,phi)Rot(y,theta)Rot(x,psi)
33
*/
34
41
42
#include <math.h>
43
#include <visp3/core/vpRzyxVector.h>
44
45
BEGIN_VISP_NAMESPACE
46
const
unsigned
int
vpRzyxVector::constr_val_3 = 3;
48
vpRzyxVector::vpRzyxVector
() :
vpRotationVector
(constr_val_3) { }
49
56
vpRzyxVector::vpRzyxVector
(
double
phi,
double
theta,
double
psi) :
vpRotationVector
(constr_val_3) {
buildFrom
(phi, theta, psi); }
57
63
vpRzyxVector::vpRzyxVector
(
const
vpRotationMatrix
&R) :
vpRotationVector
(constr_val_3) {
buildFrom
(R); }
64
71
vpRzyxVector::vpRzyxVector
(
const
vpThetaUVector
&tu) :
vpRotationVector
(constr_val_3) {
buildFrom
(tu); }
72
74
vpRzyxVector::vpRzyxVector
(
const
vpColVector
&rzyx) :
vpRotationVector
(constr_val_3) {
buildFrom
(rzyx); }
75
77
vpRzyxVector::vpRzyxVector
(
const
std::vector<double> &rzyx) :
vpRotationVector
(constr_val_3) {
buildFrom
(rzyx); }
78
88
vpRzyxVector
&
vpRzyxVector::buildFrom
(
const
vpRotationMatrix
&R)
89
{
90
const
unsigned
int
index_0 = 0;
91
const
unsigned
int
index_1 = 1;
92
const
unsigned
int
index_2 = 2;
93
double
nx = R[index_0][index_0];
94
double
ny = R[index_1][index_0];
95
96
double
COEF_MIN_ROT = 1e-6;
97
double
phi;
98
99
if
((fabs(nx) < COEF_MIN_ROT) && (fabs(ny) < COEF_MIN_ROT)) {
100
phi = 0;
101
}
102
else
{
103
phi = atan2(ny, nx);
104
}
105
double
si = sin(phi);
106
double
co = cos(phi);
107
108
double
nz = R[index_2][index_0];
109
double
theta = atan2(-nz, (co * nx) + (si * ny));
110
111
double
ax = R[index_0][index_2];
112
double
ay = R[index_1][index_2];
113
double
ox = R[index_0][index_1];
114
double
oy = R[index_1][index_1];
115
116
double
psi = atan2((si * ax) - (co * ay), (-si * ox) + (co * oy));
117
118
buildFrom
(phi, theta, psi);
119
120
return
*
this
;
121
}
122
128
vpRzyxVector
&
vpRzyxVector::buildFrom
(
const
vpThetaUVector
&tu)
129
{
130
vpRotationMatrix
R;
131
R.buildFrom(tu);
132
buildFrom
(R);
133
134
return
*
this
;
135
}
136
143
vpRzyxVector
&
vpRzyxVector::buildFrom
(
const
double
&phi,
const
double
&theta,
const
double
&psi)
144
{
145
const
unsigned
int
index_0 = 0;
146
const
unsigned
int
index_1 = 1;
147
const
unsigned
int
index_2 = 2;
148
data
[index_0] = phi;
149
data
[index_1] = theta;
150
data
[index_2] = psi;
151
return
*
this
;
152
}
153
157
vpRzyxVector
&
vpRzyxVector::buildFrom
(
const
vpColVector
&rzyx)
158
{
159
const
unsigned
int
val_3 = 3;
160
if
(rzyx.
size
() != val_3) {
161
throw
(
vpException
(
vpException::dimensionError
,
"Cannot construct a R-zyx vector from a %d-dimension col vector"
,
162
rzyx.
size
()));
163
}
164
for
(
unsigned
int
i = 0; i < val_3; ++i) {
165
data
[i] = rzyx[i];
166
}
167
168
return
*
this
;
169
}
170
174
vpRzyxVector
&
vpRzyxVector::buildFrom
(
const
std::vector<double> &rzyx)
175
{
176
const
unsigned
int
val_3 = 3;
177
if
(rzyx.size() != val_3) {
178
throw
(
vpException
(
vpException::dimensionError
,
"Cannot construct a R-zyx vector from a %d-dimension std::vector"
,
179
rzyx.size()));
180
}
181
for
(
unsigned
int
i = 0; i < val_3; ++i) {
182
data
[i] = rzyx[i];
183
}
184
185
return
*
this
;
186
}
187
211
vpRzyxVector
&
vpRzyxVector::operator=
(
double
v)
212
{
213
for
(
unsigned
int
i = 0; i <
dsize
; ++i) {
214
data
[i] = v;
215
}
216
217
return
*
this
;
218
}
219
246
vpRzyxVector
&
vpRzyxVector::operator=
(
const
vpColVector
&rzyx)
247
{
248
const
unsigned
int
val_3 = 3;
249
if
(rzyx.
size
() != val_3) {
250
throw
(
vpException
(
vpException::dimensionError
,
"Cannot set a R-zyx vector from a %d-dimension col vector"
,
251
rzyx.
size
()));
252
}
253
for
(
unsigned
int
i = 0; i < val_3; ++i) {
254
data
[i] = rzyx[i];
255
}
256
257
return
*
this
;
258
}
259
260
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
282
vpRzyxVector
&
vpRzyxVector::operator=
(
const
std::initializer_list<double> &list)
283
{
284
if
(list.size() >
size
()) {
285
throw
(
vpException
(
286
vpException::dimensionError
,
287
"Cannot set Euler x-y-z vector out of bounds. It has only %d values while you try to initialize with %d values"
,
288
size
(), list.size()));
289
}
290
std::copy(list.begin(), list.end(),
data
);
291
return
*
this
;
292
}
293
#endif
294
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
vpRzyxVector::operator=
vpRzyxVector & operator=(const vpColVector &rzyx)
Definition
vpRzyxVector.cpp:246
vpRzyxVector::buildFrom
vpRzyxVector & buildFrom(const vpRotationMatrix &R)
Definition
vpRzyxVector.cpp:88
vpRzyxVector::vpRzyxVector
vpRzyxVector()
Definition
vpRzyxVector.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
vpRzyxVector.cpp
Generated by
1.17.0