ViSP  2.8.0
vpQuaternionVector.cpp
1 /****************************************************************************
2  *
3  * $Id: vpQuaternionVector.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Quaternion vector.
36  *
37  * Authors:
38  * Filip Novotny
39  *
40  *****************************************************************************/
41 
42 
43 #include <visp/vpQuaternionVector.h>
44 #include <visp/vpMath.h>
45 #include <stdio.h>
46 #include <string.h>
47 #include <algorithm>
48 
49 
50 // minimum value of sine
51 const double vpQuaternionVector::minimum = 0.0001;
52 
58 
60 vpQuaternionVector::vpQuaternionVector(const double x, const double y,
61  const double z,const double w)
62  : vpRotationVector(4)
63 {
64  set(x, y, z, w);
65 }
66 
73  : vpRotationVector(4)
74 {
75  buildFrom(R);
76 }
82  : vpRotationVector(4)
83 {
84  for(unsigned int i=0;i<size();i++) (*this)[i]=q.r[i];
85 }
86 
94 void vpQuaternionVector::set(const double x, const double y,
95  const double z,const double w)
96 {
97  r[0]=x;
98  r[1]=y;
99  r[2]=z;
100  r[3]=w;
101 }
102 
103 
112 {
113  return vpQuaternionVector(x()+q.x(), y()+q.y(), z()+q.z(), w()+q.w());
114 }
123 {
124  return vpQuaternionVector(x()-q.x(), y()-q.y(), z()-q.z(), w()-q.w());
125 }
126 
129 {
130  return vpQuaternionVector(-x(), -y(), -z(), -w());
131 }
132 
135 {
136  return vpQuaternionVector(l*x(),l*y(),l*z(),l*w());
137 }
138 
141  return vpQuaternionVector(w() * rq.x() + x() * rq.w() + y() * rq.z() - z() * rq.y(),
142  w() * rq.y() + y() * rq.w() + z() * rq.x() - x() * rq.z(),
143  w() * rq.z() + z() * rq.w() + x() * rq.y() - y() * rq.x(),
144  w() * rq.w() - x() * rq.x() - y() * rq.y() - z() * rq.z());
145 }
146 
149 {
150  for(unsigned int i=0;i<size();i++) (*this)[i]=q.r[i];
151  return *this;
152 }
153 
160 {
161  vpThetaUVector tu(R);
162  vpColVector u;
163  double theta;
164  tu.extract(theta, u);
165 
166  theta *= 0.5;
167 
168  double sinTheta_2 = sin(theta);
169  set( u[0] * sinTheta_2, u[1] * sinTheta_2, u[2] * sinTheta_2, cos(theta) );
170 }
Class that consider the case of a generic rotation vector (cannot be used as is !) consisting in thre...
void set(const double x, const double y, const double z, const double w)
vpQuaternionVector operator-()
Negate operator. Returns a quaternion defined by (-x,-y,-z-,-w).
vpQuaternionVector operator*(const double l)
Multiplication by scalar. Returns a quaternion defined by (lx,ly,lz,lw).
double y() const
Returns y-component of the quaternion.
The vpRotationMatrix considers the particular case of a rotation matrix.
double w() const
Returns w-component of the quaternion.
void extract(double &theta, vpColVector &u) const
double z() const
Returns z-component of the quaternion.
unsigned int size() const
double x() const
Returns x-component of the quaternion.
Defines a quaternion and its basic operations.
void buildFrom(const vpRotationMatrix &R)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
vpQuaternionVector operator+(vpQuaternionVector &q)
Class that consider the case of the parameterization for the rotation.
vpQuaternionVector & operator=(vpQuaternionVector &q)
Copy operator. Allow operation such as Q = q.