Visual Servoing Platform version 3.7.0
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
46const unsigned int vpRzyxVector::constr_val_3 = 3;
49
56vpRzyxVector::vpRzyxVector(double phi, double theta, double psi) : vpRotationVector(constr_val_3) { buildFrom(phi, theta, psi); }
57
64
72
75
77vpRzyxVector::vpRzyxVector(const std::vector<double> &rzyx) : vpRotationVector(constr_val_3) { buildFrom(rzyx); }
78
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
129{
131 R.buildFrom(tu);
132 buildFrom(R);
133
134 return *this;
135}
136
143vpRzyxVector &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
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
174vpRzyxVector &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
212{
213 for (unsigned int i = 0; i < dsize; ++i) {
214 data[i] = v;
215 }
216
217 return *this;
218}
219
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)
282vpRzyxVector &vpRzyxVector::operator=(const std::initializer_list<double> &list)
283{
284 if (list.size() > size()) {
285 throw(vpException(
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
294END_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.
vpRzyxVector & operator=(const vpColVector &rzyx)
vpRzyxVector & buildFrom(const vpRotationMatrix &R)
Implementation of a rotation vector as axis-angle minimal representation.