Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
AxisAngle.cxx
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: W. Brown, M. Fischler, L. Moneta 2005
3
4 /**********************************************************************
5 * *
6 * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class AxisAngle, a rotation in 3 dimensions
12// represented by its axis and angle of rotation
13//
14// Created by: Mark Fischler Tues July 5 2005
15//
17
18#include <cmath>
19#include <algorithm>
20
24
25namespace ROOT {
26
27namespace Math {
28
29// ========== Constructors and Assignment =====================
30
32 // Note: We could require the angle to be in [0,pi) since we
33 // can represent negative angles by flipping the axis.
34 // We choose not to do this.
35
36 if ( fAngle <= Pi() && fAngle > -Pi() ) return;
37
38 if ( fAngle > 0 ) {
39 int n = static_cast<int>( (fAngle+Pi())/(2*Pi()) );
40 fAngle -= 2*Pi()*n;
41 } else {
42 int n = static_cast<int>( -(fAngle-Pi())/(2*Pi()) );
43 fAngle += 2*Pi()*n;
44 }
45} // RectifyAngle()
46
48{
49 // The two conditions are that the angle is in (-pi, pi] and
50 // the axis is a unit vector.
51
52 Scalar r2 = fAxis.Mag2();
53 if ( r2 == 0 ) {
54 fAxis.SetCoordinates(0,0,1);
55 fAngle = 0;
56 return;
57 }
58 fAxis *= (1.0/r2);
60} // Rectify()
61
62// ======== Transformation to other Rotation Forms ==================
63
65 kXX = 0, kXY = 1, kXZ = 2
66 , kYX = 3, kYY = 4, kYZ = 5
67 , kZX = 6, kZY = 7, kZZ = 8
68};
69
70
71
72// ========== Operations =====================
73
74DisplacementVector3D< Cartesian3D<double> >
76operator() (const DisplacementVector3D< Cartesian3D<double> > & v) const
77{
78 Scalar c = std::cos(fAngle);
79 Scalar s = std::sin(fAngle);
80 Scalar p = fAxis.Dot(v) * ( 1 - c );
81 return DisplacementVector3D< Cartesian3D<double> >
82 (
83 c*v.X() + p*fAxis.X() + s * (fAxis.Y()*v.Z() - fAxis.Z()*v.Y())
84 , c*v.Y() + p*fAxis.Y() + s * (fAxis.Z()*v.X() - fAxis.X()*v.Z())
85 , c*v.Z() + p*fAxis.Z() + s * (fAxis.X()*v.Y() - fAxis.Y()*v.X())
86 );
87}
88
89// ========== I/O =====================
90
91std::ostream & operator<< (std::ostream & os, const AxisAngle & a) {
92 // TODO - this will need changing for machine-readable issues
93 // and even the human readable form may need formatiing improvements
94 os << "\n" << a.Axis() << " " << a.Angle() << "\n";
95 return os;
96}
97
98
99
100} //namespace Math
101} //namespace ROOT
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition AxisAngle.h:41
static double Pi()
Definition AxisAngle.h:308
void Rectify()
Re-adjust components to eliminate small deviations from the axis being a unit vector and angles out o...
Definition AxisAngle.cxx:47
XYZVector operator()(const XYZVector &v) const
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
DisplacementVector3D< CoordSystem, Tag > & SetCoordinates(const Scalar src[])
Set internal data based on a C-style array of 3 Scalar numbers.
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.
const Int_t n
Definition legend1.C:16
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...