ViSP
Main Page
Related Pages
Modules
Classes
Examples
All
Classes
Functions
Variables
Enumerations
Enumerator
Friends
Groups
Pages
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
57
vpQuaternionVector::vpQuaternionVector
() :
vpRotationVector
(4) { }
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
72
vpQuaternionVector::vpQuaternionVector
(
const
vpRotationMatrix
&R)
73
:
vpRotationVector
(4)
74
{
75
buildFrom
(R);
76
}
81
vpQuaternionVector::vpQuaternionVector
(
const
vpQuaternionVector
&q)
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
111
vpQuaternionVector
vpQuaternionVector::operator+
(
vpQuaternionVector
&q)
112
{
113
return
vpQuaternionVector
(
x
()+q.
x
(),
y
()+q.
y
(),
z
()+q.
z
(),
w
()+q.
w
());
114
}
122
vpQuaternionVector
vpQuaternionVector::operator-
(
vpQuaternionVector
&q)
123
{
124
return
vpQuaternionVector
(
x
()-q.
x
(),
y
()-q.
y
(),
z
()-q.
z
(),
w
()-q.
w
());
125
}
126
128
vpQuaternionVector
vpQuaternionVector::operator-
()
129
{
130
return
vpQuaternionVector
(-
x
(), -
y
(), -
z
(), -
w
());
131
}
132
134
vpQuaternionVector
vpQuaternionVector::operator*
(
double
l)
135
{
136
return
vpQuaternionVector
(l*
x
(),l*
y
(),l*
z
(),l*
w
());
137
}
138
140
vpQuaternionVector
vpQuaternionVector::operator*
(
vpQuaternionVector
&rq) {
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
148
vpQuaternionVector
&
vpQuaternionVector::operator=
(
vpQuaternionVector
&q)
149
{
150
for
(
unsigned
int
i=0;i<
size
();i++) (*
this
)[i]=q.
r
[i];
151
return
*
this
;
152
}
153
159
void
vpQuaternionVector::buildFrom
(
const
vpRotationMatrix
&R)
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
}
src
math
transformation
vpQuaternionVector.cpp
Generated on Tue Sep 17 2013 00:21:37 for ViSP by
1.8.4