ViSP  2.9.0
vpQuaternionVector.cpp
1 /****************************************************************************
2  *
3  * $Id: vpQuaternionVector.cpp 4649 2014-02-07 14:57:11Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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 vpQuaternionVector::vpQuaternionVector(const double x_, const double y_,
60  const double z_,const double w_)
61  : vpRotationVector(4)
62 {
63  set(x_, y_, z_, w_);
64 }
65 
72  : vpRotationVector(4)
73 {
74  buildFrom(R);
75 }
76 
84 void vpQuaternionVector::set(const double x_, const double y_,
85  const double z_,const double w_)
86 {
87  r[0]=x_;
88  r[1]=y_;
89  r[2]=z_;
90  r[3]=w_;
91 }
92 
93 
102 {
103  return vpQuaternionVector(x()+q.x(), y()+q.y(), z()+q.z(), w()+q.w());
104 }
113 {
114  return vpQuaternionVector(x()-q.x(), y()-q.y(), z()-q.z(), w()-q.w());
115 }
116 
119 {
120  return vpQuaternionVector(-x(), -y(), -z(), -w());
121 }
122 
125 {
126  return vpQuaternionVector(l*x(),l*y(),l*z(),l*w());
127 }
128 
131  return vpQuaternionVector(w() * rq.x() + x() * rq.w() + y() * rq.z() - z() * rq.y(),
132  w() * rq.y() + y() * rq.w() + z() * rq.x() - x() * rq.z(),
133  w() * rq.z() + z() * rq.w() + x() * rq.y() - y() * rq.x(),
134  w() * rq.w() - x() * rq.x() - y() * rq.y() - z() * rq.z());
135 }
136 
143 {
144  vpThetaUVector tu(R);
145  vpColVector u;
146  double theta;
147  tu.extract(theta, u);
148 
149  theta *= 0.5;
150 
151  double sinTheta_2 = sin(theta);
152  set( u[0] * sinTheta_2, u[1] * sinTheta_2, u[2] * sinTheta_2, cos(theta) );
153 }
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.
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.