20#ifndef _vctRodriguezRotation3Base_h
21#define _vctRodriguezRotation3Base_h
39template <
class _rodriguezType,
class _matrixType>
44template <
class _rodriguezType,
class _matrixType>
66template <
class _containerType>
84 cmnThrow(std::runtime_error(
"vctRodriguezRotation3Base: This rotation is not normalized"));
92 template <
class _inputType>
94 if (! input.IsNormalized()) {
95 cmnThrow(std::runtime_error(
"vctRodriguezRotation3Base: Input is not normalized"));
109 template <str
ide_type __str
ide,
class __dataPtrType>
116 this->Assign(x, y, z);
123 template <str
ide_type __str
ide,
class __dataPtrType>
141 template <
class __vectorOwnerType>
151 template <
class __containerType>
156 return FromRaw(quaternionRotation);
160 template <
class __containerType>
163 return FromRaw(matrixRotation);
169 return FromRaw(axisAngleRotation);
174 template <str
ide_type __str
ide,
class __dataPtrType>
190 template <
class __vectorOwnerType>
199 template <
class __containerType>
206 template <
class __containerType>
220 template <str
ide_type __str
ide,
class __dataPtrType>
223 this->Assign(vector);
235 template <
class __vectorOwnerType>
238 if (vector.size() != 3) {
239 cmnThrow(std::runtime_error(
"vctRodriguezRotation3Base: From requires a vector of size 3"));
246 template <
class __containerType>
253 template <
class __containerType>
261 this->Assign(axisAngleRotation.
Axis());
268 this->NegationSelf();
273 this->NegationOf(otherRotation);
279 result.NegationOf(*
this);
285 const NormType norm = this->
Norm();
286 if (norm > (2.0 *
cmnPI)) {
287 const NormType remainder = fmod(norm, (2.0 *
cmnPI));
296 this->Assign(otherRotation);
332 const AngleType angleThis = this->
Norm();
333 const AngleType angleOther = other.Norm();
334 const AngleType dotProduct = AngleType(this->
DotProduct(other));
336 if ((angleThis <= tolerance) && (angleOther <= tolerance)) {
340 if ((angleThis <= tolerance) || (angleOther <= tolerance)) {
344 const AngleType cosAngle = dotProduct / (angleThis * angleOther);
345 const AngleType absCosAngle = cosAngle >
value_type(0.0) ? cosAngle : -cosAngle;
347 if ((absCosAngle <= (AngleType(1.0) - tolerance))
348 || (absCosAngle >= (AngleType(1.0) + tolerance))) {
352 const AngleType angleDifference = angleThis - cosAngle * angleOther;
353 AngleType angleRemain = fmod(angleDifference, 2.0 *
cmnPI);
354 if (angleRemain >
cmnPI) {
355 angleRemain -= (2.0 *
cmnPI);
356 }
else if (angleRemain < -
cmnPI) {
357 angleRemain += (2.0 *
cmnPI);
359 if ((angleRemain > -tolerance) && (angleRemain < tolerance)) {
369template <
class _rodriguezType,
class _quaternionType>
374 typedef typename _rodriguezType::value_type
value_type;
375 typedef typename _rodriguezType::AngleType AngleType;
376 typedef typename _rodriguezType::NormType NormType;
377 typedef typename _rodriguezType::TypeTraits
TypeTraits;
379 const NormType r = quaternionRotation.
R();
380 const AngleType angle = acos(r) * 2;
381 AngleType oneMinusR2 = 1.0 - r * r;
384 AngleType sinAngle = sqrt(oneMinusR2);
386 rodriguezRotation.X() = (
value_type)(quaternionRotation.X() / sinAngle);
387 rodriguezRotation.Y() = (
value_type)(quaternionRotation.Y() / sinAngle);
388 rodriguezRotation.Z() = (
value_type)(quaternionRotation.Z() / sinAngle);
390 rodriguezRotation.X() = quaternionRotation.X();
391 rodriguezRotation.Y() = quaternionRotation.Y();
392 rodriguezRotation.Z() = quaternionRotation.Z();
394 rodriguezRotation.Multiply((
value_type) angle);
398template <
class _rodriguezType,
class _matrixType>
403 typedef typename _rodriguezType::value_type
value_type;
404 typedef typename _rodriguezType::AngleType AngleType;
405 typedef typename _rodriguezType::NormType NormType;
406 typedef typename _rodriguezType::TypeTraits
TypeTraits;
409 const NormType trace = matrixRotation.Element(0, 0) + matrixRotation.Element(1, 1) + matrixRotation.Element(2, 2);
410 const NormType xSin = matrixRotation.Element(2, 1) - matrixRotation.Element(1, 2);
411 const NormType ySin = matrixRotation.Element(0, 2) - matrixRotation.Element(2, 0);
412 const NormType zSin = matrixRotation.Element(1, 0) - matrixRotation.Element(0, 1);
413 const NormType normSquare = xSin * xSin + ySin * ySin + zSin * zSin;
415 if (normSquare < normTolerance) {
418 norm = sqrt(normSquare);
423 const NormType traceMinus3 = trace - NormType(3);
425 if ( (traceMinus3 > -normTolerance) && (traceMinus3 < normTolerance) ) {
431 assert( (trace > (NormType(-1) - normTolerance)) && (trace < (NormType(-1) + normTolerance)) );
434 NormType xSquare = (matrixRotation.Element(0, 0) + 1) / 2;
435 NormType ySquare = (matrixRotation.Element(1, 1) + 1) / 2;
436 NormType zSquare = (matrixRotation.Element(2, 2) + 1) / 2;
437 if (xSquare < normTolerance)
439 if (ySquare < normTolerance)
441 if (zSquare < normTolerance)
443 NormType x = sqrt(xSquare);
444 NormType y = sqrt(ySquare);
445 NormType z = sqrt(zSquare);
448 if (matrixRotation.Element(1, 0) < 0)
450 if (matrixRotation.Element(2, 0) < 0)
453 if (matrixRotation.Element(2, 1) < 0)
464 AngleType angle = atan2(norm / 2, (trace - 1) / 2);
466 rodriguezRotation.Multiply(
value_type(angle / norm));
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition cmnTypeTraits.h:155
static Type Tolerance(void)
Definition cmnTypeTraits.h:170
_elementType value_type
Definition mtsGenericObjectProxy.h:329
Define a rotation based on an axis and an angle for a space of dimension 3.
Definition vctAxisAngleRotation3.h:93
const AxisType & Axis(void) const
Definition vctAxisAngleRotation3.h:312
ThisType Normalized(void) const
Definition vctAxisAngleRotation3.h:540
const AngleType & Angle(void) const
Definition vctAxisAngleRotation3.h:322
Definition vctForwardDeclarations.h:119
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeConstVectorBase.h:108
Define a rotation matrix for a space of dimension 3.
Definition vctMatrixRotation3Base.h:71
RotationValueType Normalized(void) const
Definition vctMatrixRotation3.h:394
const_reference R(void) const
Definition vctQuaternionBase.h:101
Define a rotation quaternion for a space of dimension 3.
Definition vctQuaternionRotation3Base.h:64
ThisType Normalized(void) const
Definition vctQuaternionRotation3Base.h:532
Define a rotation based on the rodriguez representation for a space of dimension 3.
Definition vctRodriguezRotation3Base.h:68
ThisType & From(const vctAxisAngleRotation3< value_type > &axisAngleRotation)
Definition vctRodriguezRotation3Base.h:167
ThisType & InverseOf(const ThisType &otherRotation)
Definition vctRodriguezRotation3Base.h:272
ContainerType ContainerType
Definition vctRodriguezRotation3Base.h:72
ThisType & From(const vctDynamicConstVectorBase< __vectorOwnerType, value_type > &vector) CISST_THROW(std
Definition vctRodriguezRotation3Base.h:142
ThisType & FromNormalized(const vctFixedSizeConstVectorBase< 3, __stride, value_type, __dataPtrType > &vector)
Definition vctRodriguezRotation3Base.h:175
ThisType & FromRaw(const vctDynamicConstVectorBase< __vectorOwnerType, value_type > &vector)
Definition vctRodriguezRotation3Base.h:236
ThisType & From(const vctQuaternionRotation3Base< __containerType > &quaternionRotation) CISST_THROW(std
Definition vctRodriguezRotation3Base.h:152
ThisType & From(const vctMatrixRotation3Base< __containerType > &matrixRotation)
Definition vctRodriguezRotation3Base.h:161
bool IsNormalized(value_type CMN_UNUSED(tolerance)=TypeTraits::Tolerance()) const
Definition vctRodriguezRotation3Base.h:317
ContainerType BaseType
Definition vctRodriguezRotation3Base.h:71
ThisType & FromNormalized(const vctMatrixRotation3Base< __containerType > &matrixRotation)
Definition vctRodriguezRotation3Base.h:207
ThisType & FromNormalized(const vctQuaternionRotation3Base< __containerType > &quaternionRotation)
Definition vctRodriguezRotation3Base.h:200
ThisType & InverseSelf(void)
Definition vctRodriguezRotation3Base.h:267
ThisType & FromRaw(value_type x, value_type y, value_type z)
Definition vctRodriguezRotation3Base.h:228
ThisType & FromNormalized(const vctDynamicConstVectorBase< __vectorOwnerType, value_type > &vector) CISST_THROW(std
Definition vctRodriguezRotation3Base.h:191
ThisType & NormalizedOf(const ThisType &otherRotation)
Definition vctRodriguezRotation3Base.h:295
cmnTypeTraits< value_type > TypeTraits
Definition vctRodriguezRotation3Base.h:77
@ DIMENSION
Definition vctRodriguezRotation3Base.h:70
void ThrowUnlessIsNormalized(void) const CISST_THROW(std
Definition vctRodriguezRotation3Base.h:82
ThisType & FromRaw(const vctFixedSizeConstVectorBase< 3, __stride, value_type, __dataPtrType > &vector)
Definition vctRodriguezRotation3Base.h:221
vctRodriguezRotation3Base(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &axis)
Definition vctRodriguezRotation3Base.h:110
ThisType & FromRaw(const vctQuaternionRotation3Base< __containerType > &quaternionRotation)
Definition vctRodriguezRotation3Base.h:247
ThisType Normalized(void) const
Definition vctRodriguezRotation3Base.h:302
bool AlmostEquivalent(const ThisType &other, value_type tolerance=TypeTraits::Tolerance()) const
Definition vctRodriguezRotation3Base.h:330
ThisType & FromRaw(const vctAxisAngleRotation3< value_type > &axisAngleRotation)
Definition vctRodriguezRotation3Base.h:260
ThisType & NormalizedSelf(void)
Definition vctRodriguezRotation3Base.h:284
ThisType & From(value_type x, value_type y, value_type z) CISST_THROW(std
Definition vctRodriguezRotation3Base.h:132
ThisType & FromRaw(const vctMatrixRotation3Base< __containerType > &matrixRotation)
Definition vctRodriguezRotation3Base.h:254
static CISST_EXPORT const ThisType & Identity()
ThisType & From(const vctFixedSizeConstVectorBase< 3, __stride, value_type, __dataPtrType > &vector) CISST_THROW(std
Definition vctRodriguezRotation3Base.h:124
ThisType Inverse(void) const
Definition vctRodriguezRotation3Base.h:277
ThisType & FromNormalized(value_type x, value_type y, value_type z)
Definition vctRodriguezRotation3Base.h:182
vctRodriguezRotation3Base< ContainerType > ThisType
Definition vctRodriguezRotation3Base.h:73
ThisType & FromNormalized(const vctAxisAngleRotation3< value_type > &axisAngleRotation)
Definition vctRodriguezRotation3Base.h:212
vctRodriguezRotation3Base()
Definition vctRodriguezRotation3Base.h:102
void ThrowUnlessIsNormalized(const _inputType &input) const CISST_THROW(std
Definition vctRodriguezRotation3Base.h:93
VCT_CONTAINER_TRAITS_TYPEDEFS(typename ContainerType::value_type)
vctRodriguezRotation3Base(value_type x, value_type y, value_type z)
Definition vctRodriguezRotation3Base.h:115
static OutputElementType Operate(const InputElementType &input)
Definition vctUnaryOperations.h:86
Declaration of various constants.
const double cmnPI
Definition cmnConstants.h:38
#define CISST_EXPORT
Definition cmnExportMacros.h:50
#define CMN_UNUSED(argument)
Definition cmnPortability.h:497
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition cmnThrow.h:76
cmnTypeTraits< value_type > TypeTraits
Definition vctDynamicConstMatrixBase.h:147
NormType Norm(void) const
Definition vctDynamicConstMatrixBase.h:467
value_type DotProduct(const vctDynamicConstVectorBase< __vectorOwnerType, _elementType > &otherVector) const
Definition vctDynamicConstVectorBase.h:633
Macros to export the symbols of cisstVector (in a Dll).
Declaration of vctFixedSizeVector.
Forward declarations and #define for cisstVector.
void vctRodriguezRotation3BaseFromRaw(vctRodriguezRotation3Base< _rodriguezType > &rodriguezRotation, const vctMatrixRotation3Base< _matrixType > &matrixRotation)
Definition vctRodriguezRotation3Base.h:400