CLHEP/Vector/Rotation.h

// -*- C++ -*-
// CLASSDOC OFF
// $Id: Rotation.h,v 1.12 2001/01/18 17:34:30 mf Exp $
// ---------------------------------------------------------------------------
// CLASSDOC ON
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definition of the HepRotation class for performing rotations
// on objects of the Hep3Vector (and HepLorentzVector) class.
//
// HepRotation is a concrete implementation of Hep3RotationInterface.
//
// .SS See Also
// RotationInterfaces.h
// ThreeVector.h, LorentzVector.h, LorentzRotation.h
//
// .SS Author
// Leif Lonnblad, Mark Fischler

#ifndef HEP_ROTATION_H
#define HEP_ROTATION_H

#ifdef GNUPRAGMA
#pragma interface
#endif

#include "CLHEP/Vector/RotationInterfaces.h"

#ifdef HEP_NO_INLINE_IN_DECLARATION
#define inline
#endif


// Declarations of classes and global methods
class HepRotation;
HepRotation inverseOf ( const Hep3RotationInterface & r );
HepRotation inverseOf ( const HepRotation & r );

class HepRotation : public Hep3RotationInterface {

public:

  // ----------  Constructors and Assignment:

  inline HepRotation();
  // Default constructor. Gives a unit matrix.

  inline HepRotation( const Hep3RotationInterface & m );
  inline HepRotation(const HepRotation & m);
  // Copy constructor.

  virtual HepRotation & set( const Hep3Vector & axis, HepDouble delta );
          HepRotation      ( const Hep3Vector & axis, HepDouble delta );
  // Construct from axis and angle.

  virtual HepRotation & set( const HepAxisAngle & ax );
          HepRotation      ( const HepAxisAngle & ax );
  // Construct from AxisAngle structure.

  virtual HepRotation & set( HepDouble phi, HepDouble theta, HepDouble psi );
          HepRotation      ( HepDouble phi, HepDouble theta, HepDouble psi );
  // Construct from three Euler angles (in radians).

  virtual HepRotation & set( const HepEulerAngles & e );
          HepRotation      ( const HepEulerAngles & e );
  // Construct from EulerAngles structure.

  HepRotation ( const Hep3Vector & colX,
                const Hep3Vector & colY,
                const Hep3Vector & colZ );
  // Construct from three *orthogonal* unit vector columns.
  	// NOTE:	
  	//       This constructor, and the two set methods below, 
	//	 will check that the columns (or rows) form an orthonormal 
	//	 matrix, and will adjust values so that this relation is 
	//	 as exact as possible.

  virtual HepRotation & set( const Hep3Vector & colX,
                             const Hep3Vector & colY,
                             const Hep3Vector & colZ );
  //   supply three *orthogonal* unit vectors for the columns.

  virtual HepRotation & setRows( const Hep3Vector & rowX,
                                 const Hep3Vector & rowY,
                                 const Hep3Vector & rowZ );
  //   supply three *orthogonal* unit vectors for the rows.

  virtual HepRotation & set(const Hep3RotationInterface & r);
  virtual HepRotation & operator = (const Hep3RotationInterface & r);
  inline  HepRotation & operator = (const HepRotation & r);
  // Assignment.

         HepRotation &set( const HepRep3x3 & m );
  inline HepRotation     ( const HepRep3x3 & m );
  // WARNING - NO CHECKING IS DONE!
  // Constructon directly from from a 3x3 representation,
  // which is required to be an orthogonal matrix.

  inline ~HepRotation();
  // Trivial destructor.

  // ----------  Accessors:

  inline Hep3Vector colX() const;
  inline Hep3Vector colY() const;
  inline Hep3Vector colZ() const;
  // orthogonal unit-length column vectors

  inline Hep3Vector rowX() const;
  inline Hep3Vector rowY() const;
  inline Hep3Vector rowZ() const;
  // orthogonal unit-length row vectors
                                
  inline HepDouble xx() const;
  inline HepDouble xy() const;
  inline HepDouble xz() const;
  inline HepDouble yx() const;
  inline HepDouble yy() const;
  inline HepDouble yz() const;
  inline HepDouble zx() const;
  inline HepDouble zy() const;
  inline HepDouble zz() const;
  // Elements of the rotation matrix (Geant4).

  virtual HepRep3x3 rep3x3() const;
  //   3x3 representation:

  // ------------  Subscripting:

  class HepRotation_row {
  public:
    inline HepRotation_row(const HepRotation &, int);
    inline HepDouble operator [] (int) const;
  private:
    const HepRotation & rr;
    int ii;
  };
  // Helper class for implemention of C-style subscripting r[i][j] 

  inline const HepRotation_row operator [] (int) const; 
  // Returns object of the helper class for C-style subscripting r[i][j]
  // i and j range from 0 to 2.  

  HepDouble operator () (int, int) const;
  // Fortran-style subscripting: returns (i,j) element of the rotation matrix.
  // Note:  i and j still range from 0 to 2.			[Rotation.cc]

  // ------------  Euler angles:
  inline  HepDouble getPhi  () const;
  inline  HepDouble getTheta() const;
  inline  HepDouble getPsi  () const;
  virtual HepDouble    phi  () const;
  virtual HepDouble    theta() const;
  virtual HepDouble    psi  () const;
  virtual HepEulerAngles eulerAngles() const;

  // ------------  axis & angle of rotation:
  inline  HepDouble  getDelta() const;
  inline  Hep3Vector getAxis () const;
  virtual HepDouble     delta() const;
  virtual Hep3Vector    axis () const;
  virtual HepAxisAngle  axisAngle() const;
  virtual void getAngleAxis(HepDouble & delta, Hep3Vector & axis) const;
  // Returns the rotation angle and rotation axis (Geant4). 	[Rotation.cc]

  // ------------- Angles of rotated axes
  HepDouble phiX() const;
  HepDouble phiY() const;
  HepDouble phiZ() const;
  HepDouble thetaX() const;
  HepDouble thetaY() const;
  HepDouble thetaZ() const;
  // Return angles (RADS) made by rotated axes against original axes (Geant4).
  //								[Rotation.cc]

  // ----------  Other accessors treating pure rotation as a 4-rotation

  inline HepLorentzVector col1() const;
  inline HepLorentzVector col2() const;
  inline HepLorentzVector col3() const;
  //  orthosymplectic 4-vector columns - T component will be zero

  inline HepLorentzVector col4() const;
  // Will be (0,0,0,1) for this pure Rotation.

  inline HepLorentzVector row1() const;
  inline HepLorentzVector row2() const;
  inline HepLorentzVector row3() const;
  //  orthosymplectic 4-vector rows - T component will be zero

  inline HepLorentzVector row4() const;
  // Will be (0,0,0,1) for this pure Rotation.

  inline HepDouble xt() const;
  inline HepDouble yt() const;
  inline HepDouble zt() const;
  inline HepDouble tx() const;
  inline HepDouble ty() const;
  inline HepDouble tz() const;
  // Will be zero for this pure Rotation

  inline HepDouble tt() const;
  // Will be one for this pure Rotation

  virtual HepRep4x4 rep4x4() const;
  //   4x4 representation.

  // ---------   Mutators 

  virtual void setPhi (HepDouble phi);
  // change Euler angle phi, leaving theta and psi unchanged.

  virtual void setTheta (HepDouble theta);
  // change Euler angle theta, leaving phi and psi unchanged.

  virtual void setPsi (HepDouble psi);
  // change Euler angle psi, leaving theta and phi unchanged.

  virtual void setAxis (const Hep3Vector & axis);
  // change rotation axis, leaving delta unchanged.

  virtual void setDelta (HepDouble delta);
  // change angle of rotation, leaving rotation axis unchanged.

  // ----------  Decomposition:

  virtual void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
  virtual void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
  // These are trivial, as the boost vector is 0.		[RotationP.cc]

  // ----------  Comparisons: 
  
  virtual HepBoolean isIdentity() const;				
  // Returns true if the identity matrix (Geant4).		[Rotation.cc]	

  inline int compare( const Hep3RotationInterface & r  ) const;
  // Dictionary-order comparison.  This is used in 
  // operator<, operator>, operator<=, and operator>=, which are inherited.  
  
  inline int compare( const Hep4RotationInterface & r  ) const;
  // Dictionary-order comparison.  (For completeness.)
  
  virtual HepDouble distance2( const Hep4RotationInterface & lt  ) const; 
  // 3 - Tr ( this/r ) + |b|^2 / (1-|b|^2) where b is the boost vector of lt

  virtual HepDouble distance2( const Hep3RotationInterface & r  ) const; 
  // 3 - Tr ( this/r )
  
  virtual HepDouble howNear(   const Hep4RotationInterface & lt ) const;
  virtual HepDouble howNear(   const Hep3RotationInterface & r  ) const;

  virtual HepBoolean isNear(   const Hep4RotationInterface & lt,
                                     HepDouble epsilon=tolerance) const;
  virtual HepBoolean isNear(   const Hep3RotationInterface & r,
                                     HepDouble epsilon=tolerance) const;

  // ----------  Properties:

  virtual HepDouble norm2() const; 
  // distance2 (IDENTITY), which is 3 - Tr ( *this )

  virtual void rectify();
  // non-const but logically moot correction for accumulated roundoff errors
	// rectify averages the matrix with the transpose of its actual
	// inverse (absent accumulated roundoff errors, the transpose IS
	// the inverse)); this removes to first order those errors.
	// Then it formally extracts axis and delta, and forms a true
	// HepRotation with those values of axis and delta.

  // ---------- Application:

  virtual Hep3Vector operator() (const Hep3Vector & p) const;
  // Rotate a Hep3Vector.					[Rotation.cc]

  inline  Hep3Vector operator * (const Hep3Vector & p) const;
  // Multiplication with a Hep3Vector.

  virtual HepLorentzVector operator()( const HepLorentzVector & w ) const;
  // Rotate (the space part of) a HepLorentzVector.		[Rotation.cc]

  inline  HepLorentzVector operator* ( const HepLorentzVector & w ) const;
  // Multiplication with a HepLorentzVector.

  // ---------- Operations in the group of Rotations

  virtual HepRotation operator * (const Hep3RotationInterface & r) const;
  // Product of two rotations (this) * r - matrix multiplication  [Rotation.cc]

  inline  HepRotation & operator *= (const Hep3RotationInterface & r);
  inline  HepRotation & transform   (const Hep3RotationInterface & r);
  // Matrix multiplication.
  // Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;

  HepRotation & rotateX(HepDouble delta);
  // Rotation around the x-axis; equivalent to R = RotationX(delta) * R

  HepRotation & rotateY(HepDouble delta);
  // Rotation around the y-axis; equivalent to R = RotationY(delta) * R

  HepRotation & rotateZ(HepDouble delta);
  // Rotation around the z-axis; equivalent to R = RotationZ(delta) * R

         HepRotation & rotate(HepDouble delta, const Hep3Vector & axis);
  inline HepRotation & rotate(HepDouble delta, const Hep3Vector * axis);
  // Rotation around a specified vector.  
  // r.rotate(d,a) is equivalent to r = Rotation(d,a) * r

  HepRotation & rotateAxes(const Hep3Vector & newX,
                           const Hep3Vector & newY,
                           const Hep3Vector & newZ);
  // Rotation of local axes defined by 3 orthonormal vectors (Geant4).
  // Equivalent to r = Rotation (newX, newY, newZ) * r

  inline HepRotation inverse() const;
  // Returns the inverse.

  friend HepRotation inverseOf ( const Hep3RotationInterface & r );
  friend HepRotation inverseOf ( const HepRotation & r );
  // global methods to invert.

  inline HepRotation & invert();
  // Inverts the Rotation matrix.

  // ---------- I/O: 

  virtual HepStd::ostream & print( HepStd::ostream & os ) const;
  // Aligned six-digit-accurate output of the  rotation matrix.	[RotationIO.cc]

  // ---------- Identity Rotation:

  static const HepRotation IDENTITY;

protected:

  inline HepRotation(HepDouble mxx, HepDouble mxy, HepDouble mxz, 
		     HepDouble myx, HepDouble myy, HepDouble myz,
		     HepDouble mzx, HepDouble mzy, HepDouble mzz);
  // Protected constructor.  
  // DOES NOT CHECK FOR VALIDITY AS A ROTATION.

  HepDouble rxx, rxy, rxz, 
	    ryx, ryy, ryz, 
	    rzx, rzy, rzz;
  // The matrix elements.

private:
  HepBoolean 
       setCols ( const Hep3Vector & u1,	// Vectors assume to be of unit length 
                 const Hep3Vector & u2,
                 const Hep3Vector & u3,
                 HepDouble u1u2,
                 Hep3Vector & v1,		// Returned vectors
                 Hep3Vector & v2,
                 Hep3Vector & v3 ) const;
  void setArbitrarily (const Hep3Vector & colX, // assumed to be of unit length
                      Hep3Vector & v1,
                      Hep3Vector & v2,
                      Hep3Vector & v3) const;
};

#ifdef HEP_NO_INLINE_IN_DECLARATION
#undef inline
#endif

#ifdef HEP_SHORT_NAMES
typedef HepRotation Rotation;
#endif

#ifndef HEP_DEBUG_INLINE
#include "CLHEP/Vector/Rotation.icc"
#endif

#endif /* HEP_ROTATION_H */


Generated by GNU enscript 1.6.1.