22 #ifndef _vctAxisAngleRotation3_h
23 #define _vctAxisAngleRotation3_h
42 template <
class _elementType,
class _containerType>
47 template <
class _elementType,
class _containerType>
52 template <
class _elementType,
class _containerType>
57 #ifdef CISST_COMPILER_IS_MSVC
93 template <
class _elementType>
111 if (! IsNormalized()) {
112 cmnThrow(std::runtime_error(
"vctAxisAngleRotation3: This rotation is not normalized"));
120 template <
class _inputType>
122 if (! input.IsNormalized()) {
123 cmnThrow(std::runtime_error(
"vctAxisAngleRotation3: Input is not normalized"));
131 AxisMember(1.0, 0.0, 0.0),
137 inline ThisType &
Assign(
const ThisType & other) {
139 AngleMember = other.
Angle();
163 template <str
ide_type __str
ide,
class __dataPtrType>
165 const AngleType angle)
166 throw(std::runtime_error)
175 template <
class _vectorOwnerType>
178 throw(std::runtime_error)
184 template <
class _containerType>
187 throw(std::runtime_error)
189 From(quaternionRotation);
193 template <
class _containerType>
196 throw(std::runtime_error)
198 From(matrixRotation);
202 template <
class _containerType>
205 throw(std::runtime_error)
207 From(rodriguezRotation);
240 template <str
ide_type __str
ide,
class __dataPtrType>
242 const AngleType angle,
245 if (normalizeInput) {
246 FromNormalized(axis, angle);
248 FromRaw(axis, angle);
257 template <
class _vectorOwnerType>
262 if (normalizeInput) {
263 FromNormalized(axis, angle);
265 FromRaw(axis, angle);
270 template <
class _containerType>
274 if (normalizeInput) {
275 FromNormalized(quaternionRotation);
277 FromRaw(quaternionRotation);
282 template <
class _containerType>
286 if (normalizeInput) {
287 FromNormalized(matrixRotation);
289 FromRaw(matrixRotation);
294 template <
class _containerType>
298 if (normalizeInput) {
299 FromNormalized(rodriguezRotation);
301 FromRaw(rodriguezRotation);
314 inline const AxisType &
Axis(
void)
const {
324 inline const AngleType &
Angle(
void)
const {
349 template <str
ide_type __str
ide,
class __dataPtrType>
351 const AngleType angle)
352 throw(std::runtime_error)
354 FromRaw(axis, angle);
355 ThrowUnlessIsNormalized();
360 template <
class _vectorOwnerType>
363 throw(std::runtime_error)
365 AxisMember[0] = axis[0];
366 AxisMember[1] = axis[1];
367 AxisMember[2] = axis[2];
369 ThrowUnlessIsNormalized();
374 template <
class _containerType>
376 throw(std::runtime_error)
378 ThrowUnlessIsNormalized(quaternionRotation);
379 return FromRaw(quaternionRotation);
383 template <
class _containerType>
385 throw(std::runtime_error)
387 ThrowUnlessIsNormalized(matrixRotation);
388 return FromRaw(matrixRotation);
392 template <
class _containerType>
394 throw(std::runtime_error)
396 ThrowUnlessIsNormalized(rodriguezRotation);
397 return FromRaw(rodriguezRotation);
415 template <str
ide_type __str
ide,
class __dataPtrType>
417 const AngleType angle)
419 FromRaw(axis, angle);
425 template <
class _containerType>
427 return FromRaw(quaternionRotation.
Normalized());
431 template <
class _containerType>
437 template <
class _containerType>
439 return FromRaw(rodriguezRotation.
Normalized());
456 template <str
ide_type __str
ide,
class __dataPtrType>
458 const AngleType angle)
466 template <
class _containerType>
473 template <
class _containerType>
480 template <
class _containerType>
494 AngleMember = 2.0 *
cmnPI - AngleMember;
500 inline ThisType &
InverseOf(
const ThisType & otherRotation) {
502 AngleMember = 2.0 *
cmnPI - otherRotation.
Angle();
520 AngleMember = fmod(AngleMember, 2.0 *
cmnPI);
521 if (AngleMember < 0.0) {
522 AngleMember += (2.0 *
cmnPI);
534 AngleMember = otherRotation.
Angle();
543 ThisType result(*
this);
554 inline bool IsNormalized(value_type tolerance = TypeTraits::Tolerance())
const {
566 inline bool Equal(
const ThisType & other)
const {
567 return ((this->Angle() == other.
Angle()) && (this->Axis().Equal(other.
Axis())));
571 return this->Equal(other);
586 value_type tolerance = TypeTraits::Tolerance())
const {
587 const AngleType angleDiff = this->Angle() - other.
Angle();
588 const AngleType angle = (angleDiff < 0) ? -angleDiff : angleDiff;
590 return ((angle <= tolerance) && (this->Axis().AlmostEqual(other.
Axis(), tolerance)));
606 value_type tolerance = TypeTraits::Tolerance())
const {
607 const AngleType angleThis = this->Angle();
608 const AngleType angleOther = other.
Angle();
610 if ((angleThis <= tolerance) && (angleOther <= tolerance)) {
614 if ((angleThis <= tolerance) || (angleOther <= tolerance)) {
619 const AngleType dotProduct = AngleType(this->Axis().Normalized().DotProduct(other.
Axis().
Normalized()));
620 const AngleType absDotProduct = dotProduct > value_type(0.0) ? dotProduct : -dotProduct;
622 if ((absDotProduct <= (AngleType(1.0) - tolerance))
623 || (absDotProduct >= (AngleType(1.0) + tolerance))) {
627 const AngleType angleDifference = angleThis - dotProduct * angleOther;
628 AngleType angleRemain = fmod(angleDifference, 2.0 *
cmnPI);
629 if (angleRemain >
cmnPI) {
630 angleRemain -= (2.0 *
cmnPI);
631 }
else if (angleRemain < -
cmnPI) {
632 angleRemain += (2.0 *
cmnPI);
634 if ((angleRemain > -tolerance) && (angleRemain < tolerance)) {
642 std::stringstream outputStream;
643 ToStream(outputStream);
644 return outputStream.str();
649 outputStream <<
"axis: "
659 void ToStreamRaw(std::ostream & outputStream,
const char delimiter =
' ',
660 bool headerOnly =
false,
const std::string & headerPrefix =
"")
const {
661 this->Axis().ToStreamRaw(outputStream, delimiter, headerOnly, headerPrefix +
"axis-");
662 outputStream << delimiter;
664 outputStream << headerPrefix <<
"angle";
666 outputStream << this->Angle();
673 this->Axis().SerializeRaw(outputStream);
680 this->Axis().DeSerializeRaw(inputStream);
688 template<
class _elementType>
696 #endif // _vctAxisAngleRotation3_h
vctFixedSizeVector< value_type, DIMENSION > AxisType
Definition: vctAxisAngleRotation3.h:101
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
vctAxisAngleRotation3(const vctMatrixRotation3Base< _containerType > &matrixRotation, bool normalizeInput)
Definition: vctAxisAngleRotation3.h:283
bool AlmostEquivalent(const ThisType &other, value_type tolerance=TypeTraits::Tolerance()) const
Definition: vctAxisAngleRotation3.h:605
vctAxisAngleRotation3(const vctRodriguezRotation3Base< _containerType > &rodriguezRotation, bool normalizeInput)
Definition: vctAxisAngleRotation3.h:295
ThisType & Assign(const ThisType &other)
Definition: vctAxisAngleRotation3.h:137
const AxisType & Axis(void) const
Definition: vctAxisAngleRotation3.h:314
vctAxisAngleRotation3(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &axis, const AngleType angle)
Definition: vctAxisAngleRotation3.h:164
RotationValueType Normalized(void) const
Definition: vctMatrixRotation3.h:389
ThisType & From(const vctQuaternionRotation3Base< _containerType > &quaternionRotation)
Definition: vctAxisAngleRotation3.h:375
std::string ToString(void) const
Definition: vctAxisAngleRotation3.h:641
AngleType & Angle(void)
Definition: vctAxisAngleRotation3.h:329
AngleType AngleMember
Definition: vctAxisAngleRotation3.h:106
ThisType & FromNormalized(const vctQuaternionRotation3Base< _containerType > &quaternionRotation)
Definition: vctAxisAngleRotation3.h:426
ThisType & FromRaw(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &axis, const AngleType angle)
Definition: vctAxisAngleRotation3.h:457
cmnTypeTraits< _elementType > TypeTraits
Definition: vctAxisAngleRotation3.h:102
vctAxisAngleRotation3()
Definition: vctAxisAngleRotation3.h:130
ThisType & FromRaw(const vctMatrixRotation3Base< _containerType > &matrixRotation)
Definition: vctAxisAngleRotation3.h:474
void SerializeRaw(std::ostream &outputStream) const
Definition: vctAxisAngleRotation3.h:671
ThisType & NormalizedSelf(void)
Definition: vctFixedSizeVectorBase.h:1363
ThisType & FromNormalized(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &axis, const AngleType angle)
Definition: vctAxisAngleRotation3.h:416
vctAxisAngleRotation3(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &axis, const AngleType angle, bool normalizeInput)
Definition: vctAxisAngleRotation3.h:241
AxisType & Axis(void)
Definition: vctAxisAngleRotation3.h:319
vctAxisAngleRotation3(const vctMatrixRotation3Base< _containerType > &matrixRotation)
Definition: vctAxisAngleRotation3.h:195
ThisType & From(const vctMatrixRotation3Base< _containerType > &matrixRotation)
Definition: vctAxisAngleRotation3.h:384
Declaration of various constants.
#define VCT_CONTAINER_TRAITS_TYPEDEFS(type)
Definition: vctContainerTraits.h:50
ThisType & Assign(const vctFixedSizeConstVectorBase< _size, __stride, __elementType, __dataPtrType > &other)
Definition: vctFixedSizeVectorBase.h:274
vctAxisAngleRotation3< value_type > ThisType
Definition: vctAxisAngleRotation3.h:100
ThisType & From(const vctDynamicConstVectorBase< _vectorOwnerType, value_type > &axis, AngleType angle)
Definition: vctAxisAngleRotation3.h:361
ThisType Normalized(void) const
Definition: vctQuaternionRotation3Base.h:529
ThisType & From(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &axis, const AngleType angle)
Definition: vctAxisAngleRotation3.h:350
ThisType & FromNormalized(const vctMatrixRotation3Base< _containerType > &matrixRotation)
Definition: vctAxisAngleRotation3.h:432
Declaration of vctDynamicVector.
Define a rotation based on an axis and an angle for a space of dimension 3.
Definition: vctAxisAngleRotation3.h:94
ThisType & NormalizedSelf(void)
Definition: vctAxisAngleRotation3.h:518
bool Equal(const ThisType &other) const
Definition: vctAxisAngleRotation3.h:566
ThisType Inverse(void) const
Definition: vctAxisAngleRotation3.h:509
Define a rotation matrix for a space of dimension 3.
Definition: vctForwardDeclarations.h:199
ThisType & From(const vctRodriguezRotation3Base< _containerType > &rodriguezRotation)
Definition: vctAxisAngleRotation3.h:393
ThisType Normalized(void) const
Definition: vctAxisAngleRotation3.h:542
Declaration of vctFixedSizeVector.
void cmnDeSerializeRaw(std::istream &inputStream, _elementType &data)
Definition: cmnDeSerializer.h:82
vctAxisAngleRotation3(const vctDynamicConstVectorBase< _vectorOwnerType, value_type > &axis, AngleType angle)
Definition: vctAxisAngleRotation3.h:176
ThisType Normalized(void) const
Definition: vctRodriguezRotation3Base.h:304
std::ostream & operator<<(std::ostream &output, const vctAxisAngleRotation3< _elementType > &axisAngle)
Definition: vctAxisAngleRotation3.h:689
void cmnSerializeRaw(std::ostream &outputStream, const _elementType &data)
Definition: cmnSerializer.h:78
Declaration of vctRodriguezRotation3Base.
vctAxisAngleRotation3(const vctQuaternionRotation3Base< _containerType > &quaternionRotation, bool normalizeInput)
Definition: vctAxisAngleRotation3.h:271
vctAxisAngleRotation3(const vctRodriguezRotation3Base< _containerType > &rodriguezRotation)
Definition: vctAxisAngleRotation3.h:204
ThisType & FromNormalized(const vctRodriguezRotation3Base< _containerType > &rodriguezRotation)
Definition: vctAxisAngleRotation3.h:438
void ThrowUnlessIsNormalized(void) const
Definition: vctAxisAngleRotation3.h:110
#define cmnThrow(a)
Definition: MinimalCmn.h:4
void DeSerializeRaw(std::istream &inputStream)
Definition: vctAxisAngleRotation3.h:678
void ToStream(std::ostream &outputStream) const
Definition: vctAxisAngleRotation3.h:648
void ToStreamRaw(std::ostream &outputStream, const char delimiter= ' ', bool headerOnly=false, const std::string &headerPrefix="") const
Definition: vctAxisAngleRotation3.h:659
void vctAxisAngleRotation3FromRaw(vctAxisAngleRotation3< _elementType > &axisAngleRotation, const vctQuaternionRotation3Base< _containerType > &quaternionRotation)
ThisType & FromRaw(const vctQuaternionRotation3Base< _containerType > &quaternionRotation)
Definition: vctAxisAngleRotation3.h:467
vctAxisAngleRotation3(const vctDynamicConstVectorBase< _vectorOwnerType, value_type > &axis, AngleType angle, bool normalizeInput)
Definition: vctAxisAngleRotation3.h:258
bool AlmostEqual(const ThisType &other, value_type tolerance=TypeTraits::Tolerance()) const
Definition: vctAxisAngleRotation3.h:585
const AngleType & Angle(void) const
Definition: vctAxisAngleRotation3.h:324
Declaration of vctMatrixRotation3Base.
VectorValueType Normalized(void) const
Definition: vctFixedSizeVector.h:569
bool operator==(const ThisType &other) const
Definition: vctAxisAngleRotation3.h:570
Definition: vctDynamicConstVectorBase.h:77
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeConstVectorBase.h:107
ThisType & FromRaw(const vctRodriguezRotation3Base< _containerType > &rodriguezRotation)
Definition: vctAxisAngleRotation3.h:481
ThisType & InverseOf(const ThisType &otherRotation)
Definition: vctAxisAngleRotation3.h:500
bool IsNormalized(_elementType tolerance=cmnTypeTraits< _elementType >::Tolerance()) const
Definition: vctFixedSizeConstVectorBase.h:461
void ThrowUnlessIsNormalized(const _inputType &input) const
Definition: vctAxisAngleRotation3.h:121
Declaration of vctQuaternionRotation3Base.
Define a rotation quaternion for a space of dimension 3.
Definition: vctForwardDeclarations.h:208
AxisType AxisMember
Definition: vctAxisAngleRotation3.h:105
Macros to export the symbols of cisstVector (in a Dll).
bool IsNormalized(value_type tolerance=TypeTraits::Tolerance()) const
Definition: vctAxisAngleRotation3.h:554
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition: cmnTypeTraits.h:155
vctAxisAngleRotation3(const vctQuaternionRotation3Base< _containerType > &quaternionRotation)
Definition: vctAxisAngleRotation3.h:186
const double cmnPI
Definition: cmnConstants.h:38
Define a rotation based on the rodriguez representation for a space of dimension 3.
Definition: vctForwardDeclarations.h:214
ThisType & NormalizedOf(const ThisType &otherRotation)
Definition: vctAxisAngleRotation3.h:532
ThisType & InverseSelf(void)
Definition: vctAxisAngleRotation3.h:493