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
26
28
29namespace ROOT {
30
31namespace ROOT_MATH_ARCH {
32
33// ========== Constructors and Assignment =====================
34
36{
37 // Note: We could require the angle to be in [0,pi) since we
38 // can represent negative angles by flipping the axis.
39 // We choose not to do this.
40
41 if (fAngle <= Pi() && fAngle > -Pi())
42 return;
43
44 if (fAngle > 0) {
45 int n = static_cast<int>((fAngle + Pi()) / (2 * Pi()));
46 fAngle -= 2 * Pi() * n;
47 } else {
48 int n = static_cast<int>(-(fAngle - Pi()) / (2 * Pi()));
49 fAngle += 2 * Pi() * n;
50 }
51} // RectifyAngle()
52
54{
55 // The two conditions are that the angle is in (-pi, pi] and
56 // the axis is a unit vector.
57
58 Scalar r2 = fAxis.Mag2();
59 if (r2 == 0) {
60 fAxis.SetCoordinates(0, 0, 1);
61 fAngle = 0;
62 return;
63 }
64 fAxis *= (1.0 / r2);
66} // Rectify()
67
68// ======== Transformation to other Rotation Forms ==================
69
71 kXX = 0,
72 kXY = 1,
73 kXZ = 2,
74 kYX = 3,
75 kYY = 4,
76 kYZ = 5,
77 kZX = 6,
78 kZY = 7,
79 kZZ = 8
80};
81
82// ========== Operations =====================
83
85{
88 Scalar p = fAxis.Dot(v) * (1 - c);
90 c * v.X() + p * fAxis.X() + s * (fAxis.Y() * v.Z() - fAxis.Z() * v.Y()),
91 c * v.Y() + p * fAxis.Y() + s * (fAxis.Z() * v.X() - fAxis.X() * v.Z()),
92 c * v.Z() + p * fAxis.Z() + s * (fAxis.X() * v.Y() - fAxis.Y() * v.X()));
93}
94
95#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
96// ========== I/O =====================
97
98std::ostream &operator<<(std::ostream &os, const AxisAngle &a)
99{
100 // TODO - this will need changing for machine-readable issues
101 // and even the human readable form may need formatting improvements
102 os << "\n" << a.Axis() << " " << a.Angle() << "\n";
103 return os;
104}
105#endif
106
107} // namespace ROOT_MATH_ARCH
108} // namespace ROOT
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition AxisAngle.h:46
XYZVector operator()(const XYZVector &v) const
Definition AxisAngle.cxx:84
void Rectify()
Re-adjust components to eliminate small deviations from the axis being a unit vector and angles out o...
Definition AxisAngle.cxx:53
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
Rotation operation on a cartesian vector.
Definition AxisAngle.h:209
const Int_t n
Definition legend1.C:16
Scalar math_cos(Scalar x)
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition AxisAngle.cxx:98
Scalar math_sin(Scalar x)