Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpRzyzVector.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 * Euler angles parameterization for the rotation.
32 * Rzyz(phi,theta,psi) = Rot(z,phi)Rot(y,theta)Rot(z,psi)
33 */
34
40
41#include <math.h>
42#include <visp3/core/vpRzyzVector.h>
43
45const unsigned int vpRzyzVector::constr_val_3 = 3;
48
55vpRzyzVector::vpRzyzVector(double phi, double theta, double psi) : vpRotationVector(constr_val_3) { buildFrom(phi, theta, psi); }
56
63
71
74
76vpRzyzVector::vpRzyzVector(const std::vector<double> &rzyz) : vpRotationVector(constr_val_3) { buildFrom(rzyz); }
77
85{
86 double phi;
87 const unsigned int index_0 = 0;
88 const unsigned int index_1 = 1;
89 const unsigned int index_2 = 2;
90 if ((fabs(R[index_1][index_2]) < 1e-6) && (fabs(R[index_0][index_2]) < 1e-6)) {
91 phi = 0;
92 }
93 else {
94 phi = atan2(R[index_1][index_2], R[index_0][index_2]);
95 }
96 double cphi = cos(phi);
97 double sphi = sin(phi);
98
99 double theta = atan2((cphi * R[index_0][index_2]) + (sphi * R[index_1][index_2]), R[index_2][index_2]);
100
101 double psi = atan2((-sphi * R[0][0]) + (cphi * R[1][0]), (-sphi * R[0][1]) + (cphi * R[1][1]));
102
103 buildFrom(phi, theta, psi);
104
105 return *this;
106}
107
114{
116 R.buildFrom(tu);
117 buildFrom(R);
118
119 return *this;
120}
121
126{
127 const unsigned int val_3 = 3;
128 if (rzyz.size() != val_3) {
129 throw(vpException(vpException::dimensionError, "Cannot construct a R-zyz vector from a %d-dimension col vector",
130 rzyz.size()));
131 }
132 for (unsigned int i = 0; i < val_3; ++i) {
133 data[i] = rzyz[i];
134 }
135
136 return *this;
137}
138
142vpRzyzVector &vpRzyzVector::buildFrom(const std::vector<double> &rzyz)
143{
144 const unsigned int val_3 = 3;
145 if (rzyz.size() != val_3) {
146 throw(vpException(vpException::dimensionError, "Cannot construct a R-zyx vector from a %d-dimension std::vector",
147 rzyz.size()));
148 }
149 for (unsigned int i = 0; i < val_3; ++i) {
150 data[i] = rzyz[i];
151 }
152
153 return *this;
154}
155
162vpRzyzVector &vpRzyzVector::buildFrom(const double &phi, const double &theta, const double &psi)
163{
164 const unsigned int index_0 = 0;
165 const unsigned int index_1 = 1;
166 const unsigned int index_2 = 2;
167 data[index_0] = phi;
168 data[index_1] = theta;
169 data[index_2] = psi;
170 return *this;
171}
172
197{
198 for (unsigned int i = 0; i < dsize; ++i) {
199 data[i] = v;
200 }
201
202 return *this;
203}
204
232{
233 const unsigned int val_3 = 3;
234 if (rzyz.size() != val_3) {
235 throw(vpException(vpException::dimensionError, "Cannot set a R-zyz vector from a %d-dimension col vector",
236 rzyz.size()));
237 }
238 for (unsigned int i = 0; i < val_3; ++i) {
239 data[i] = rzyz[i];
240 }
241
242 return *this;
243}
244
245#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
267vpRzyzVector &vpRzyzVector::operator=(const std::initializer_list<double> &list)
268{
269 if (list.size() > size()) {
270 throw(vpException(
272 "Cannot set Euler x-y-z vector out of bounds. It has only %d values while you try to initialize with %d values",
273 size(), list.size()));
274 }
275 std::copy(list.begin(), list.end(), data);
276 return *this;
277}
278#endif
279END_VISP_NAMESPACE
unsigned int dsize
Definition vpArray2D.h:1207
unsigned int size() const
Return the number of elements of the 2D array.
Definition vpArray2D.h:435
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ dimensionError
Bad dimension.
Definition vpException.h:71
Implementation of a rotation matrix and operations on such kind of matrices.
vpRotationVector()
Constructor that constructs a 0-size rotation vector.
vpRzyzVector & buildFrom(const vpRotationMatrix &R)
vpRzyzVector & operator=(const vpColVector &rzyz)
Implementation of a rotation vector as axis-angle minimal representation.