Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JGEOMETRY3D::JQuaternion3D Class Reference

Data structure for unit quaternion in three dimensions. More...

#include <JQuaternion3D.hh>

Inheritance diagram for JGEOMETRY3D::JQuaternion3D:
JMATH::JMath< JFirst_t, JSecond_t > JMATH::JMath< JFirst_t, JSecond_t > JMATH::JMath< JFirst_t, JSecond_t > JMATH::JMath< JFirst_t, JSecond_t > JLANG::JEquals< JFirst_t, JSecond_t > JCOMPASS::JHit JDETECTOR::JCompassRotation_t JDETECTOR::JModule JDETECTOR::JModuleRotation_t JCALIBRATE::JModel JMONITOR::JClusterBuilder

Classes

struct  decomposition
 Auxiliary data structure for decomposition of quaternion in twist and swing quaternions. More...
 

Public Member Functions

 JQuaternion3D ()
 Default constructor.
 
 JQuaternion3D (const double a, const double b, const double c, const double d)
 Constructor.
 
 JQuaternion3D (const double theta, const JVersor3D &dir)
 Constructor.
 
 JQuaternion3D (const double w, const JVector3D &dir)
 Constructor.
 
 JQuaternion3D (const JQuaternion3X &qx)
 Constructor.
 
 JQuaternion3D (const JQuaternion3Y &qy)
 Constructor.
 
 JQuaternion3D (const JQuaternion3Z &qz)
 Constructor.
 
 JQuaternion3D (const JQuaternion3X &qx, const JQuaternion3Y &qy, const JQuaternion3Z &qz)
 Constructor.
 
const JQuaternion3DgetQuaternion () const
 Get quaternion.
 
JQuaternion3DgetQuaternion ()
 Get quaternion.
 
void setQuaternion (const JQuaternion3D &quaternion)
 Set quaternion.
 
 operator JVector3D () const
 Type conversion operator.
 
 operator JVersor3D () const
 Type conversion operator.
 
double getAngle () const
 Get rotation angle.
 
double getA () const
 Get a value.
 
double getB () const
 Get b value.
 
double getC () const
 Get c value.
 
double getD () const
 Get d value.
 
JQuaternion3DsetIdentity ()
 Set to identity quaternion.
 
JQuaternion3Dconjugate ()
 Conjugate quaternion.
 
JQuaternion3Dnegate ()
 Negate quaternion.
 
JQuaternion3Dadd (const JQuaternion3D &quaternion)
 Add quaternion.
 
JQuaternion3Dsub (const JQuaternion3D &quaternion)
 Subtract quaternion.
 
JQuaternion3Dmul (const double factor)
 Scale quaternion.
 
JQuaternion3Ddiv (const double factor)
 Scale quaternion.
 
JQuaternion3Dmul (const JQuaternion3D &first, const JQuaternion3X &second)
 Quaternion multiplication.
 
JQuaternion3Dmul (const JQuaternion3D &first, const JQuaternion3Y &second)
 Quaternion multiplication.
 
JQuaternion3Dmul (const JQuaternion3D &first, const JQuaternion3Z &second)
 Quaternion multiplication.
 
JQuaternion3Dmul (const JQuaternion3D &first, const JQuaternion3D &second)
 Quaternion multiplication.
 
JQuaternion3Dmul (const JQuaternion3X &qx, const JQuaternion3Y &qy, const JQuaternion3Z &qz)
 Quaternion multiplication.
 
void rotate (double &__x, double &__y, double &__z) const
 Rotate.
 
void rotate_back (double &__x, double &__y, double &__z) const
 Rotate back.
 
bool equals (const JQuaternion3D &quaternion, const double precision=std::numeric_limits< double >::min()) const
 Check equality.
 
bool isIdentity (const double precision=std::numeric_limits< double >::min()) const
 Test identity.
 
double getLengthSquared () const
 Get length squared.
 
double getLength () const
 Get length.
 
double getDistanceSquared (const JQuaternion3D &quaternion) const
 Get squared of distance to quaternion.
 
double getDistance (const JQuaternion3D &quaternion) const
 Get distance to quaternion.
 
double getDot (const JQuaternion3D &quaternion) const
 Get dot product.
 
JQuaternion3D getConjugate () const
 Get conjugate of this quaternion.
 
JQuaternion3Dnormalise ()
 Normalise quaternion.
 
JQuaternion3Dpow (const double y)
 Raise quaternion to given power.
 
JQuaternion3Dinterpolate (const JQuaternion3D &object, const double alpha)
 Interpolation between quaternions.
 
JFirst_t & mul (const JSecond_t &object)
 Multiply with object.
 

Static Public Member Functions

static const JQuaternion3DgetIdentity ()
 Get identity quaternion.
 

Protected Attributes

double __a
 
double __b
 
double __c
 
double __d
 

Friends

std::istream & operator>> (std::istream &in, JQuaternion3D &quaternion)
 Write quaternion from input.
 
std::ostream & operator<< (std::ostream &out, const JQuaternion3D &quaternion)
 Write quaternion to output.
 
JReaderoperator>> (JReader &in, JQuaternion3D &quaternion)
 Read quaternion from input.
 
JWriteroperator<< (JWriter &out, const JQuaternion3D &quaternion)
 Write quaternion to output.
 

Detailed Description

Data structure for unit quaternion in three dimensions.

This class implements the JMATH::JMath and JLANG::JEquals interfaces.

Definition at line 303 of file JQuaternion3D.hh.

Constructor & Destructor Documentation

◆ JQuaternion3D() [1/8]

JGEOMETRY3D::JQuaternion3D::JQuaternion3D ( )
inline

Default constructor.

Definition at line 324 of file JQuaternion3D.hh.

◆ JQuaternion3D() [2/8]

JGEOMETRY3D::JQuaternion3D::JQuaternion3D ( const double a,
const double b,
const double c,
const double d )
inline

Constructor.

Parameters
aa value
bb value
cc value
dd value

Definition at line 340 of file JQuaternion3D.hh.

343 :
344 __a(a),
345 __b(b),
346 __c(c),
347 __d(d)
348 {
349 normalise();
350 }
JQuaternion3D & normalise()
Normalise quaternion.

◆ JQuaternion3D() [3/8]

JGEOMETRY3D::JQuaternion3D::JQuaternion3D ( const double theta,
const JVersor3D & dir )
inline

Constructor.

This constructor represents a rotation around the given axis by the given angle.

Parameters
thetarotation angle [rad]
dirrotation axis

Definition at line 361 of file JQuaternion3D.hh.

363 {
364 const double ct = cos(0.5*theta);
365 const double st = sin(0.5*theta);
366
367 __a = ct;
368 __b = st * dir.getDX();
369 __c = st * dir.getDY();
370 __d = st * dir.getDZ();
371 }

◆ JQuaternion3D() [4/8]

JGEOMETRY3D::JQuaternion3D::JQuaternion3D ( const double w,
const JVector3D & dir )
inline

Constructor.

Parameters
wweight
dirrotation axis

Definition at line 380 of file JQuaternion3D.hh.

382 {
383 __a = w;
384 __b = dir.getX();
385 __c = dir.getY();
386 __d = dir.getZ();
387
388 normalise();
389 }

◆ JQuaternion3D() [5/8]

JGEOMETRY3D::JQuaternion3D::JQuaternion3D ( const JQuaternion3X & qx)
inline

Constructor.

Parameters
qxrotation around x-axis

Definition at line 397 of file JQuaternion3D.hh.

397 :
398 __a(1.0),
399 __b(0.0),
400 __c(0.0),
401 __d(0.0)
402 {
403 mul(qx);
404 }
JQuaternion3D & mul(const double factor)
Scale quaternion.

◆ JQuaternion3D() [6/8]

JGEOMETRY3D::JQuaternion3D::JQuaternion3D ( const JQuaternion3Y & qy)
inline

Constructor.

Parameters
qyrotation around y-axis

Definition at line 412 of file JQuaternion3D.hh.

412 :
413 __a(1.0),
414 __b(0.0),
415 __c(0.0),
416 __d(0.0)
417 {
418 mul(qy);
419 }

◆ JQuaternion3D() [7/8]

JGEOMETRY3D::JQuaternion3D::JQuaternion3D ( const JQuaternion3Z & qz)
inline

Constructor.

Parameters
qzrotation around x-axis

Definition at line 427 of file JQuaternion3D.hh.

427 :
428 __a(1.0),
429 __b(0.0),
430 __c(0.0),
431 __d(0.0)
432 {
433 mul(qz);
434 }

◆ JQuaternion3D() [8/8]

JGEOMETRY3D::JQuaternion3D::JQuaternion3D ( const JQuaternion3X & qx,
const JQuaternion3Y & qy,
const JQuaternion3Z & qz )
inline

Constructor.

Parameters
qxrotation around x-axis
qyrotation around y-axis
qzrotation around z-axis

Definition at line 444 of file JQuaternion3D.hh.

446 :
447 __a(1.0),
448 __b(0.0),
449 __c(0.0),
450 __d(0.0)
451 {
452 mul(qz).mul(qy).mul(qx);
453
454 normalise();
455 }

Member Function Documentation

◆ getIdentity()

static const JQuaternion3D & JGEOMETRY3D::JQuaternion3D::getIdentity ( )
inlinestatic

Get identity quaternion.

Returns
identity quaternion

Definition at line 463 of file JQuaternion3D.hh.

464 {
465 static const JQuaternion3D Q = JQuaternion3D().setIdentity();
466
467 return Q;
468 }
JQuaternion3D()
Default constructor.

◆ getQuaternion() [1/2]

const JQuaternion3D & JGEOMETRY3D::JQuaternion3D::getQuaternion ( ) const
inline

Get quaternion.

Returns
quaternion

Definition at line 476 of file JQuaternion3D.hh.

477 {
478 return static_cast<const JQuaternion3D&>(*this);
479 }

◆ getQuaternion() [2/2]

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::getQuaternion ( )
inline

Get quaternion.

Returns
quaternion

Definition at line 487 of file JQuaternion3D.hh.

488 {
489 return static_cast<JQuaternion3D&>(*this);
490 }

◆ setQuaternion()

void JGEOMETRY3D::JQuaternion3D::setQuaternion ( const JQuaternion3D & quaternion)
inline

Set quaternion.

Parameters
quaternionquaternion

Definition at line 498 of file JQuaternion3D.hh.

499 {
500 static_cast<JQuaternion3D&>(*this) = quaternion;
501 }

◆ operator JVector3D()

JGEOMETRY3D::JQuaternion3D::operator JVector3D ( ) const
inline

Type conversion operator.

Returns
position

Definition at line 509 of file JQuaternion3D.hh.

510 {
511 return JVector3D(this->getB(), this->getC(), this->getD());
512 }
double getB() const
Get b value.
double getD() const
Get d value.
double getC() const
Get c value.

◆ operator JVersor3D()

JGEOMETRY3D::JQuaternion3D::operator JVersor3D ( ) const
inline

Type conversion operator.

Returns
direction

Definition at line 520 of file JQuaternion3D.hh.

521 {
522 return JVersor3D(this->getB(), this->getC(), this->getD());
523 }

◆ getAngle()

double JGEOMETRY3D::JQuaternion3D::getAngle ( ) const
inline

Get rotation angle.

Returns
angle [rad]

Definition at line 531 of file JQuaternion3D.hh.

532 {
533 return atan2(sqrt(this->getB()*this->getB() +
534 this->getC()*this->getC() +
535 this->getD()*this->getD()),
536 this->getA()) * 2.0;
537 }
double getA() const
Get a value.

◆ getA()

double JGEOMETRY3D::JQuaternion3D::getA ( ) const
inline

Get a value.

Returns
a value

Definition at line 545 of file JQuaternion3D.hh.

546 {
547 return __a;
548 }

◆ getB()

double JGEOMETRY3D::JQuaternion3D::getB ( ) const
inline

Get b value.

Returns
b value

Definition at line 556 of file JQuaternion3D.hh.

557 {
558 return __b;
559 }

◆ getC()

double JGEOMETRY3D::JQuaternion3D::getC ( ) const
inline

Get c value.

Returns
c value

Definition at line 567 of file JQuaternion3D.hh.

568 {
569 return __c;
570 }

◆ getD()

double JGEOMETRY3D::JQuaternion3D::getD ( ) const
inline

Get d value.

Returns
d value

Definition at line 578 of file JQuaternion3D.hh.

579 {
580 return __d;
581 }

◆ setIdentity()

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::setIdentity ( )
inline

Set to identity quaternion.

Returns
this quaternion

Definition at line 589 of file JQuaternion3D.hh.

590 {
591 __a = 1.0;
592 __b = 0.0;
593 __c = 0.0;
594 __d = 0.0;
595
596 return *this;
597 }

◆ conjugate()

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::conjugate ( )
inline

Conjugate quaternion.

Returns
this quaternion

Definition at line 605 of file JQuaternion3D.hh.

606 {
607 __b = -__b;
608 __c = -__c;
609 __d = -__d;
610
611 return *this;
612 }

◆ negate()

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::negate ( )
inline

Negate quaternion.

Returns
this quaternion

Definition at line 620 of file JQuaternion3D.hh.

621 {
622 __a = -__a;
623 __b = -__b;
624 __c = -__c;
625 __d = -__d;
626
627 return *this;
628 }

◆ add()

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::add ( const JQuaternion3D & quaternion)
inline

Add quaternion.

Parameters
quaternionquaternion
Returns
this quaternion

Definition at line 637 of file JQuaternion3D.hh.

638 {
639 __a += quaternion.getA();
640 __b += quaternion.getB();
641 __c += quaternion.getC();
642 __d += quaternion.getD();
643
644 return *this;
645 }

◆ sub()

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::sub ( const JQuaternion3D & quaternion)
inline

Subtract quaternion.

Parameters
quaternionquaternion
Returns
this quaternion

Definition at line 654 of file JQuaternion3D.hh.

655 {
656 __a -= quaternion.getA();
657 __b -= quaternion.getB();
658 __c -= quaternion.getC();
659 __d -= quaternion.getD();
660
661 return *this;
662 }

◆ mul() [1/7]

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::mul ( const double factor)
inline

Scale quaternion.

Parameters
factormultiplication factor
Returns
this quaternion

Definition at line 671 of file JQuaternion3D.hh.

672 {
673 __a *= factor;
674 __b *= factor;
675 __c *= factor;
676 __d *= factor;
677
678 return *this;
679 }

◆ div()

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::div ( const double factor)
inline

Scale quaternion.

Parameters
factordivision factor
Returns
this quaternion

Definition at line 688 of file JQuaternion3D.hh.

689 {
690 __a /= factor;
691 __b /= factor;
692 __c /= factor;
693 __d /= factor;
694
695 return *this;
696 }

◆ mul() [2/7]

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::mul ( const JQuaternion3D & first,
const JQuaternion3X & second )
inline

Quaternion multiplication.

This method evaluates the Hamilton product (also called cross product).

Parameters
firstfirst quaternion
secondsecond quaternion
Returns
this quaternion

Definition at line 708 of file JQuaternion3D.hh.

709 {
710 __a = first.getA() * second.getA() - first.getB() * second.getB();
711 __b = first.getA() * second.getB() + first.getB() * second.getA();
712 __c = first.getC() * second.getA() + first.getD() * second.getB();
713 __d = -first.getC() * second.getB() + first.getD() * second.getA();
714
715 return *this;
716 }

◆ mul() [3/7]

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::mul ( const JQuaternion3D & first,
const JQuaternion3Y & second )
inline

Quaternion multiplication.

This method evaluates the Hamilton product (or cross product).

Parameters
firstfirst quaternion
secondsecond quaternion
Returns
this quaternion

Definition at line 728 of file JQuaternion3D.hh.

730 {
731 __a = first.getA() * second.getA() - first.getC() * second.getC();
732 __b = first.getB() * second.getA() - first.getD() * second.getC();
733 __c = first.getA() * second.getC() + first.getC() * second.getA();
734 __d = first.getB() * second.getC() + first.getD() * second.getA();
735
736 return *this;
737 }

◆ mul() [4/7]

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::mul ( const JQuaternion3D & first,
const JQuaternion3Z & second )
inline

Quaternion multiplication.

This method evaluates the Hamilton product (or cross product).

Parameters
firstfirst quaternion
secondsecond quaternion
Returns
this quaternion

Definition at line 749 of file JQuaternion3D.hh.

751 {
752 __a = first.getA() * second.getA() - first.getD() * second.getD();
753 __b = first.getB() * second.getA() + first.getC() * second.getD();
754 __c = -first.getB() * second.getD() + first.getC() * second.getA();
755 __d = first.getA() * second.getD() + first.getD() * second.getA();
756
757 return *this;
758 }

◆ mul() [5/7]

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::mul ( const JQuaternion3D & first,
const JQuaternion3D & second )
inline

Quaternion multiplication.

This method evaluates the Hamilton product (or cross product).

Parameters
firstfirst quaternion
secondsecond quaternion
Returns
this quaternion

Definition at line 770 of file JQuaternion3D.hh.

772 {
773 __a = first.getA() * second.getA() - first.getB() * second.getB() - first.getC() * second.getC() - first.getD() * second.getD();
774 __b = first.getA() * second.getB() + first.getB() * second.getA() + first.getC() * second.getD() - first.getD() * second.getC();
775 __c = first.getA() * second.getC() - first.getB() * second.getD() + first.getC() * second.getA() + first.getD() * second.getB();
776 __d = first.getA() * second.getD() + first.getB() * second.getC() - first.getC() * second.getB() + first.getD() * second.getA();
777
778 return *this;
779 }

◆ mul() [6/7]

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::mul ( const JQuaternion3X & qx,
const JQuaternion3Y & qy,
const JQuaternion3Z & qz )
inline

Quaternion multiplication.

Parameters
qxrotation around x-axis
qyrotation around y-axis
qzrotation around x-axis
Returns
this quaternion

Definition at line 790 of file JQuaternion3D.hh.

793 {
794 return *this = JQuaternion3D().setIdentity().mul(qz).mul(qy).mul(qx);
795 }

◆ rotate()

void JGEOMETRY3D::JQuaternion3D::rotate ( double & __x,
double & __y,
double & __z ) const
inline

Rotate.

Parameters
__xx value
__yy value
__zz value

Definition at line 805 of file JQuaternion3D.hh.

806 {
807 const double qx = 2.0 * (__c*__z - __d*__y);
808 const double qy = 2.0 * (__d*__x - __b*__z);
809 const double qz = 2.0 * (__b*__y - __c*__x);
810
811 __x = __x + __c*qz - __d*qy + __a*qx;
812 __y = __y - __b*qz + __a*qy + __d*qx;
813 __z = __z + __a*qz + __b*qy - __c*qx;
814 }

◆ rotate_back()

void JGEOMETRY3D::JQuaternion3D::rotate_back ( double & __x,
double & __y,
double & __z ) const
inline

Rotate back.

Parameters
__xx value
__yy value
__zz value

Definition at line 824 of file JQuaternion3D.hh.

825 {
826 const double qx = 2.0 * (__d*__y - __c*__z);
827 const double qy = 2.0 * (__b*__z - __d*__x);
828 const double qz = 2.0 * (__c*__x - __b*__y);
829
830 __x = __x - __c*qz + __d*qy + __a*qx;
831 __y = __y + __b*qz + __a*qy - __d*qx;
832 __z = __z + __a*qz - __b*qy + __c*qx;
833 }

◆ equals()

bool JGEOMETRY3D::JQuaternion3D::equals ( const JQuaternion3D & quaternion,
const double precision = std::numeric_limits<double>::min() ) const
inline

Check equality.

Parameters
quaternionquaternion
precisionnumerical precision
Returns
true if quaternions are equal; else false

Definition at line 843 of file JQuaternion3D.hh.

845 {
846 return (fabs(getA() - quaternion.getA()) <= precision &&
847 fabs(getB() - quaternion.getB()) <= precision &&
848 fabs(getC() - quaternion.getC()) <= precision &&
849 fabs(getD() - quaternion.getD()) <= precision);
850 }

◆ isIdentity()

bool JGEOMETRY3D::JQuaternion3D::isIdentity ( const double precision = std::numeric_limits<double>::min()) const
inline

Test identity.

Parameters
precisionprecision
Returns
true if identity quaternion; else false

Definition at line 859 of file JQuaternion3D.hh.

860 {
861 if (fabs(getA()) <= precision) {
862
863 if (fabs(getB()) <= precision)
864 return ((fabs(getC()) <= precision && fabs(fabs(getD()) - 1.0) <= precision) ||
865 (fabs(fabs(getC()) - 1.0) <= precision && fabs(getD()) <= precision));
866 else
867 return (fabs(fabs(getB()) - 1.0) <= precision &&
868 fabs(getC()) <= precision &&
869 fabs(getD()) <= precision);
870
871 } else {
872
873 return (fabs(fabs(getA()) - 1.0) <= precision &&
874 fabs(getB()) <= precision &&
875 fabs(getC()) <= precision &&
876 fabs(getD()) <= precision);
877 }
878 }

◆ getLengthSquared()

double JGEOMETRY3D::JQuaternion3D::getLengthSquared ( ) const
inline

Get length squared.

Returns
square of length

Definition at line 886 of file JQuaternion3D.hh.

887 {
888 return getA()*getA() + getB()*getB() + getC()*getC() + getD()*getD();
889 }

◆ getLength()

double JGEOMETRY3D::JQuaternion3D::getLength ( ) const
inline

Get length.

Returns
length

Definition at line 897 of file JQuaternion3D.hh.

898 {
899 return sqrt(getLengthSquared());
900 }
double getLengthSquared() const
Get length squared.

◆ getDistanceSquared()

double JGEOMETRY3D::JQuaternion3D::getDistanceSquared ( const JQuaternion3D & quaternion) const
inline

Get squared of distance to quaternion.

Parameters
quaternionquaternion
Returns
square of distance

Definition at line 909 of file JQuaternion3D.hh.

910 {
911 return JQuaternion3D(quaternion).sub(*this).getLengthSquared();
912 }

◆ getDistance()

double JGEOMETRY3D::JQuaternion3D::getDistance ( const JQuaternion3D & quaternion) const
inline

Get distance to quaternion.

Parameters
quaternionquaternion
Returns
distance

Definition at line 921 of file JQuaternion3D.hh.

922 {
923 return sqrt(getDistanceSquared(quaternion));
924 }
double getDistanceSquared(const JQuaternion3D &quaternion) const
Get squared of distance to quaternion.

◆ getDot()

double JGEOMETRY3D::JQuaternion3D::getDot ( const JQuaternion3D & quaternion) const
inline

Get dot product.

Parameters
quaternionquaternion
Returns
dot product

Definition at line 933 of file JQuaternion3D.hh.

934 {
935 return
936 getA() * quaternion.getA() -
937 getB() * quaternion.getB() -
938 getC() * quaternion.getC() -
939 getD() * quaternion.getD();
940 }

◆ getConjugate()

JQuaternion3D JGEOMETRY3D::JQuaternion3D::getConjugate ( ) const
inline

Get conjugate of this quaternion.

Returns
conjugate quaternion

Definition at line 948 of file JQuaternion3D.hh.

949 {
950 return JQuaternion3D(*this).conjugate();
951 }

◆ normalise()

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::normalise ( )
inline

Normalise quaternion.

Returns
this quaternion

Definition at line 959 of file JQuaternion3D.hh.

960 {
961 const double v = getLength();
962
963 if (v != 0.0) {
964 mul(1.0 / v);
965 }
966
967 return *this;
968 }
double getLength() const
Get length.

◆ pow()

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::pow ( const double y)
inline

Raise quaternion to given power.

Parameters
ypower
Returns
this object

Definition at line 977 of file JQuaternion3D.hh.

978 {
979 const double v = sqrt(getB() * getB() +
980 getC() * getC() +
981 getD() * getD());
982
983 if (v != 0.0) {
984
985 const JVersor3D u(getB(), getC(), getD());
986
987 const double theta = atan2(v, getA());
988
989 *this = JQuaternion3D(2.0 * theta * y, u);
990 }
991
992 return *this;
993 }

◆ interpolate()

JQuaternion3D & JGEOMETRY3D::JQuaternion3D::interpolate ( const JQuaternion3D & object,
const double alpha )
inline

Interpolation between quaternions.

The result is equal to *this = (1 - alpha) * (*this) + (alpha) * (object).

Parameters
objectobject
alphainterpolation factor [0, 1]
Returns
this object

Definition at line 1004 of file JQuaternion3D.hh.

1006 {
1007 const double MAXIMAL_DOT_PRODUCT = 0.9995;
1008
1009 JQuaternion3D v0(*this);
1010 JQuaternion3D v1(object);
1011
1012 v0.normalise();
1013 v1.normalise();
1014
1015 double dot = v0.getDot(v1);
1016
1017 if (dot < 0.0) {
1018 v1 = -v1;
1019 dot = -dot;
1020 }
1021
1022 double s1 = alpha;
1023 double s0 = 1.0 - alpha;
1024
1025 if (dot <= MAXIMAL_DOT_PRODUCT) {
1026
1027 const double theta_0 = acos(dot);
1028 const double theta_1 = theta_0 * alpha;
1029
1030 s1 = sin(theta_1) / sin(theta_0);
1031 s0 = cos(theta_1) - dot * s1;
1032 }
1033
1034 *this = (s0 * v0) + (s1 * v1);
1035
1036 return normalise();
1037 }

◆ mul() [7/7]

template<class JFirst_t , class JSecond_t >
JFirst_t & JMATH::JMath< JFirst_t, JSecond_t >::mul ( const JSecond_t & object)
inlineinherited

Multiply with object.

Parameters
objectobject
Returns
result object

Definition at line 354 of file JMath.hh.

355 {
356 return static_cast<JFirst_t&>(*this) = JFirst_t().mul(static_cast<const JFirst_t&>(*this), object);
357 }

Friends And Related Symbol Documentation

◆ operator>> [1/2]

std::istream & operator>> ( std::istream & in,
JQuaternion3D & quaternion )
friend

Write quaternion from input.

Parameters
ininput stream
quaternionquaternion
Returns
input stream

Definition at line 1047 of file JQuaternion3D.hh.

1048 {
1049 in >> quaternion.__a;
1050 in >> quaternion.__b;
1051 in >> quaternion.__c;
1052 in >> quaternion.__d;
1053
1054 quaternion.normalise();
1055
1056 return in;
1057 }

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream & out,
const JQuaternion3D & quaternion )
friend

Write quaternion to output.

Parameters
outoutput stream
quaternionquaternion
Returns
output stream

Definition at line 1067 of file JQuaternion3D.hh.

1068 {
1069 const JFormat format(out, getFormat<JQuaternion3D>(JFormat_t(9, 6, std::ios::fixed | std::ios::showpos)));
1070
1071 out << format << quaternion.getA() << ' '
1072 << format << quaternion.getB() << ' '
1073 << format << quaternion.getC() << ' '
1074 << format << quaternion.getD();
1075
1076 return out;
1077 }
JFormat_t & getFormat()
Get format for given type.
Definition JManip.hh:682
Data structure for format specifications.
Definition JManip.hh:524
Auxiliary class to temporarily define format specifications.
Definition JManip.hh:636

◆ operator>> [2/2]

JReader & operator>> ( JReader & in,
JQuaternion3D & quaternion )
friend

Read quaternion from input.

Parameters
inreader
quaternionquaternion
Returns
reader

Definition at line 1087 of file JQuaternion3D.hh.

1088 {
1089 in >> quaternion.__a;
1090 in >> quaternion.__b;
1091 in >> quaternion.__c;
1092 in >> quaternion.__d;
1093
1094 return in;
1095 }

◆ operator<< [2/2]

JWriter & operator<< ( JWriter & out,
const JQuaternion3D & quaternion )
friend

Write quaternion to output.

Parameters
outwriter
quaternionquaternion
Returns
writer

Definition at line 1105 of file JQuaternion3D.hh.

1106 {
1107 out << quaternion.__a;
1108 out << quaternion.__b;
1109 out << quaternion.__c;
1110 out << quaternion.__d;
1111
1112 return out;
1113 }

Member Data Documentation

◆ __a

double JGEOMETRY3D::JQuaternion3D::__a
protected

Definition at line 1117 of file JQuaternion3D.hh.

◆ __b

double JGEOMETRY3D::JQuaternion3D::__b
protected

Definition at line 1118 of file JQuaternion3D.hh.

◆ __c

double JGEOMETRY3D::JQuaternion3D::__c
protected

Definition at line 1119 of file JQuaternion3D.hh.

◆ __d

double JGEOMETRY3D::JQuaternion3D::__d
protected

Definition at line 1120 of file JQuaternion3D.hh.


The documentation for this class was generated from the following file: