cisst-saw
Loading...
Searching...
No Matches
vctQuaternionBase.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5
6 Author(s): Anton Deguet
7 Created on: 2005-08-18
8
9 (C) Copyright 2005-2007 Johns Hopkins University (JHU), All Rights
10 Reserved.
11
12--- begin cisst license - do not edit ---
13
14This software is provided "as is" under an open source license, with
15no warranty. The complete license can be found in license.txt and
16http://www.cisst.org/cisst/license.txt.
17
18--- end cisst license ---
19*/
20
21#pragma once
22#ifndef _vctQuaternionBase_h
23#define _vctQuaternionBase_h
24
29
33// always the last file to include
35
36
48template <class _containerType>
49class vctQuaternionBase: public _containerType
50{
51protected:
56 inline void Allocate(void) {}
57
58 public:
59 enum {SIZE = 4};
60 typedef _containerType BaseType;
61 typedef _containerType ContainerType;
63
64 /* no need to document, inherit doxygen documentation from base class */
65 VCT_CONTAINER_TRAITS_TYPEDEFS(typename ContainerType::value_type);
67
68
70 inline vctQuaternionBase(void)
71 {
72 this->Allocate();
73 }
74
75
83 inline vctQuaternionBase(const value_type & x,
84 const value_type & y,
85 const value_type & z,
86 const value_type & r)
87 {
88 this->Allocate();
89 this->X() = x;
90 this->Y() = y;
91 this->Z() = z;
92 this->R() = r;
93 }
94
95
96 /* Methods X, Y, Z are inherited, add methods R() */
97
101 const_reference R(void) const {
102 return *(this->Pointer(3));
103 }
104
108 reference R(void) {
109 return *(this->Pointer(3));
110 }
111
112
115 template <class __containerTypeOther>
117 this->X() = - otherQuaternion.X();
118 this->Y() = - otherQuaternion.Y();
119 this->Z() = - otherQuaternion.Z();
120 this->R() = otherQuaternion.R();
121 return *this;
122 }
123
124
126 inline ThisType & ConjugateSelf(void) {
127 this->X() = - this->X();
128 this->Y() = - this->Y();
129 this->Z() = - this->Z();
130 return *this;
131 }
132
133
136 inline ThisType Conjugate(void) const {
137 ThisType result;
138 result.ConjugateOf(*this);
139 return result;
140 }
141
142
148 template <class __containerType1, class __containerType2>
151 this->X() = quat1.R() * quat2.X() + quat1.X() * quat2.R() + quat1.Y() * quat2.Z() - quat1.Z() * quat2.Y();
152 this->Y() = quat1.R() * quat2.Y() - quat1.X() * quat2.Z() + quat1.Y() * quat2.R() + quat1.Z() * quat2.X();
153 this->Z() = quat1.R() * quat2.Z() + quat1.X() * quat2.Y() - quat1.Y() * quat2.X() + quat1.Z() * quat2.R();
154 this->R() = quat1.R() * quat2.R() - quat1.X() * quat2.X() - quat1.Y() * quat2.Y() - quat1.Z() * quat2.Z();
155 return *this;
156 }
157
160 template <class __containerType1, class __containerType2>
163 const value_type quat2Norm = value_type(quat2.Norm());
164 BaseType quat2I;
165 quat2I.Assign(-quat2.X() / quat2Norm, -quat2.Y() / quat2Norm, -quat2.Z() / quat2Norm, quat2.R() / quat2Norm);
166 this->X() = quat1.R() * quat2I.X() + quat1.X() * quat2.R() + quat1.Y() * quat2I.Z() - quat1.Z() * quat2I.Y();
167 this->Y() = quat1.R() * quat2I.Y() - quat1.X() * quat2I.Z() + quat1.Y() * quat2.R() + quat1.Z() * quat2I.X();
168 this->Z() = quat1.R() * quat2I.Z() + quat1.X() * quat2I.Y() - quat1.Y() * quat2I.X() + quat1.Z() * quat2.R();
169 this->R() = quat1.R() * quat2.R() - quat1.X() * quat2I.X() - quat1.Y() * quat2I.Y() - quat1.Z() * quat2I.Z();
170 return *this;
171 }
172
176 template <class __containerTypeOther>
178 ThisType result;
179 result = ProductOf(*this, other);
180 *this = result;
181 return *this;
182 }
183
187 template <class __containerTypeOther>
189 ThisType result;
190 result = ProductOf(other, *this);
191 *this = result;
192 return *this;
193 }
194
196 template <class __containerTypeOther>
198 ThisType result;
199 result.QuotientOf(*this, other);
200 *this = result;
201 return *this;
202 }
203
208 inline ThisType & Divide(const value_type s) {
209 (static_cast<BaseType *>(this))->Divide(s);
210 return *this;
211 }
212
213};
214
215
216/* Specialization of Allocate for a dynamic matrix */
217template<>
219{
220 this->SetSize(SIZE);
221}
222
223template<>
225{
226 this->SetSize(SIZE);
227}
228
229
230
237template <class _containerType>
240 const vctQuaternionBase<_containerType> & quat2) {
242 result.ProductOf(quat1, quat2);
243 return result;
244}
245
246
253template <class _containerType>
256 const vctQuaternionBase<_containerType> & quat2) {
258 result.QuotientOf(quat1, quat2);
259 return result;
260}
261
262
263#endif // _vctQuaternionBase_h
264
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition cmnTypeTraits.h:155
_elementType value_type
Definition mtsGenericObjectProxy.h:329
ThisType & Assign(const vctDynamicConstNArrayBase< __nArrayOwnerType, value_type, DIMENSION > &other)
Definition vctDynamicNArrayBase.h:370
Define a quaternion container.
Definition vctQuaternionBase.h:50
ThisType & Divide(const vctQuaternionBase< __containerTypeOther > &other)
Definition vctQuaternionBase.h:197
@ SIZE
Definition vctQuaternionBase.h:59
ContainerType BaseType
Definition vctQuaternionBase.h:60
void Allocate(void)
Definition vctQuaternionBase.h:56
cmnTypeTraits< value_type > TypeTraits
Definition vctQuaternionBase.h:66
ThisType Conjugate(void) const
Definition vctQuaternionBase.h:136
ThisType & ConjugateSelf(void)
Definition vctQuaternionBase.h:126
ThisType & ProductOf(const vctQuaternionBase< __containerType1 > &quat1, const vctQuaternionBase< __containerType2 > &quat2)
Definition vctQuaternionBase.h:149
VCT_CONTAINER_TRAITS_TYPEDEFS(typename ContainerType::value_type)
vctQuaternionBase(const value_type &x, const value_type &y, const value_type &z, const value_type &r)
Definition vctQuaternionBase.h:83
const_reference R(void) const
Definition vctQuaternionBase.h:101
vctQuaternionBase(void)
Definition vctQuaternionBase.h:70
ThisType & QuotientOf(const vctQuaternionBase< __containerType1 > &quat1, const vctQuaternionBase< __containerType2 > &quat2)
Definition vctQuaternionBase.h:161
ContainerType ContainerType
Definition vctQuaternionBase.h:61
ThisType & Divide(const value_type s)
Definition vctQuaternionBase.h:208
ThisType & PostMultiply(const vctQuaternionBase< __containerTypeOther > &other)
Definition vctQuaternionBase.h:177
reference R(void)
Definition vctQuaternionBase.h:108
vctQuaternionBase< ContainerType > ThisType
Definition vctQuaternionBase.h:62
ThisType & ConjugateOf(const vctQuaternionBase< __containerTypeOther > &otherQuaternion)
Definition vctQuaternionBase.h:116
ThisType & PreMultiply(const vctQuaternionBase< __containerTypeOther > &other)
Definition vctQuaternionBase.h:188
Declaration of the class cmnTypeTraits.
Basic traits for the cisstVector containers.
const_pointer Pointer(index_type rowIndex, index_type colIndex) const
Definition vctDynamicConstMatrixBase.h:306
const value_type & Y(void) const
Definition vctDynamicConstVectorBase.h:271
const value_type & Z(void) const
Definition vctDynamicConstVectorBase.h:279
const value_type & X(void) const
Definition vctDynamicConstVectorBase.h:263
void SetSize(size_type rows, size_type cols, bool storageOrder)
Definition vctDynamicMatrix.h:364
Declaration of vctDynamicVector.
Macros to export the symbols of cisstVector (in a Dll).
vctQuaternionBase< _containerType > operator*(const vctQuaternionBase< _containerType > &quat1, const vctQuaternionBase< _containerType > &quat2)
Definition vctQuaternionBase.h:239
vctQuaternionBase< _containerType > operator/(const vctQuaternionBase< _containerType > &quat1, const vctQuaternionBase< _containerType > &quat2)
Definition vctQuaternionBase.h:255