Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpRxyzVector.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See https://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * Rxyz angle parameterization for the rotation.
33 * Rxyz(phi,theta,psi) = Rot(x,phi)Rot(y,theta)Rot(z,psi).
34 *
35*****************************************************************************/
36
37#include <math.h>
38
39#include <visp3/core/vpRxyzVector.h>
40
49
52
59vpRxyzVector::vpRxyzVector(double phi, double theta, double psi) : vpRotationVector(3) { buildFrom(phi, theta, psi); }
60
67
75
78
80vpRxyzVector::vpRxyzVector(const std::vector<double> &rxyz) : vpRotationVector(3) { buildFrom(rxyz); }
81
90{
91 double COEF_MIN_ROT = 1e-6;
92 double phi;
93
94 if ((fabs(R[1][2]) < COEF_MIN_ROT) && (fabs(R[2][2]) < COEF_MIN_ROT))
95 phi = 0;
96 else
97 phi = atan2(-R[1][2], R[2][2]);
98
99 double si = sin(phi);
100 double co = cos(phi);
101 double theta = atan2(R[0][2], -si * R[1][2] + co * R[2][2]);
102 double psi = atan2(co * R[1][0] + si * R[2][0], co * R[1][1] + si * R[2][1]);
103
104 buildFrom(phi, theta, psi);
105
106 return *this;
107}
108
116{
118 R.buildFrom(tu);
119 buildFrom(R);
120
121 return *this;
122}
123
130void vpRxyzVector::buildFrom(double phi, double theta, double psi)
131{
132 data[0] = phi;
133 data[1] = theta;
134 data[2] = psi;
135}
136
141{
142 if (rxyz.size() != 3) {
143 throw(vpException(vpException::dimensionError, "Cannot construct a R-xyz vector from a %d-dimension col vector",
144 rxyz.size()));
145 }
146 for (unsigned int i = 0; i < 3; i++)
147 data[i] = rxyz[i];
148
149 return *this;
150}
151
155vpRxyzVector vpRxyzVector::buildFrom(const std::vector<double> &rxyz)
156{
157 if (rxyz.size() != 3) {
158 throw(vpException(vpException::dimensionError, "Cannot construct a R-xyz vector from a %d-dimension std::vector",
159 rxyz.size()));
160 }
161 for (unsigned int i = 0; i < 3; i++)
162 data[i] = rxyz[i];
163
164 return *this;
165}
166
187{
188 for (unsigned int i = 0; i < dsize; i++)
189 data[i] = v;
190
191 return *this;
192}
193
218{
219 if (rxyz.size() != 3) {
220 throw(vpException(vpException::dimensionError, "Cannot set a R-xyz vector from a %d-dimension col vector",
221 rxyz.size()));
222 }
223 for (unsigned int i = 0; i < 3; i++)
224 data[i] = rxyz[i];
225
226 return *this;
227}
228
229#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
247vpRxyzVector &vpRxyzVector::operator=(const std::initializer_list<double> &list)
248{
249 if (list.size() > size()) {
250 throw(vpException(
252 "Cannot set Euler x-y-z vector out of bounds. It has only %d values while you try to initialize with %d values",
253 size(), list.size()));
254 }
255 std::copy(list.begin(), list.end(), data);
256 return *this;
257}
258#endif
unsigned int dsize
Definition vpArray2D.h:140
unsigned int size() const
Return the number of elements of the 2D array.
Definition vpArray2D.h:292
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:59
@ dimensionError
Bad dimension.
Definition vpException.h:83
Implementation of a rotation matrix and operations on such kind of matrices.
vpRotationMatrix buildFrom(const vpHomogeneousMatrix &M)
Implementation of a generic rotation vector.
Implementation of a rotation vector as Euler angle minimal representation.
vpRxyzVector buildFrom(const vpRotationMatrix &R)
vpRxyzVector & operator=(const vpColVector &rxyz)
Implementation of a rotation vector as axis-angle minimal representation.