/usr/include/root/Math/GenVector/AxisAngle.h is in libroot-math-genvector-dev 5.34.30-0ubuntu8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | // @(#)root/mathcore:$Id$
// Authors: W. Brown, M. Fischler, L. Moneta 2005
/**********************************************************************
* *
* Copyright (c) 2005 , LCG ROOT MathLib Team *
* *
* *
**********************************************************************/
// Header file for class AxisAngle
//
// Created by: Lorenzo Moneta at Wed May 11 10:37:10 2005
//
// Last update: Wed May 11 10:37:10 2005
//
#ifndef ROOT_Math_GenVector_AxisAngle
#define ROOT_Math_GenVector_AxisAngle 1
#include "Math/GenVector/Rotation3D.h"
#include "Math/GenVector/DisplacementVector3D.h"
#include "Math/GenVector/PositionVector3D.h"
#include "Math/GenVector/LorentzVector.h"
#include "Math/GenVector/3DConversions.h"
#include <algorithm>
#include <cassert>
namespace ROOT {
namespace Math {
//__________________________________________________________________________________________
/**
AxisAngle class describing rotation represented with direction axis (3D Vector) and an
angle of rotation around that axis.
@ingroup GenVector
*/
class AxisAngle {
public:
typedef double Scalar;
/**
definition of vector axis
*/
typedef DisplacementVector3D<Cartesian3D<Scalar> > AxisVector;
/**
Default constructor (axis is z and angle is zero)
*/
AxisAngle() : fAxis(0,0,1), fAngle(0) { }
/**
Construct from a non-zero vector (x,y,z) and an angle.
Precondition: the Vector needs to implement x(), y(), z(), and unit()
*/
template<class AnyVector>
AxisAngle(const AnyVector & v, Scalar angle) :
fAxis(v.unit()), fAngle(angle) { }
/**
Construct given a pair of pointers or iterators defining the
beginning and end of an array of four Scalars, to be treated as
the x, y, and z components of a unit axis vector, and the angle
of rotation.
Precondition: The first three components are assumed to represent
the rotation axis vector and the 4-th the rotation angle.
The angle is assumed to be in the range (-pi,pi].
The axis vector is automatically normalized to be a unit vector
*/
template<class IT>
AxisAngle(IT begin, IT end) { SetComponents(begin,end); }
// The compiler-generated copy ctor, copy assignment, and dtor are OK.
/**
Re-adjust components to eliminate small deviations from the axis
being a unit vector and angles out of the canonical range (-pi,pi]
*/
void Rectify();
// ======== Construction From other Rotation Forms ==================
/**
Construct from another supported rotation type (see gv_detail::convert )
*/
template <class OtherRotation>
explicit AxisAngle(const OtherRotation & r) {gv_detail::convert(r,*this);}
/**
Assign from another supported rotation type (see gv_detail::convert )
*/
template <class OtherRotation>
AxisAngle & operator=( OtherRotation const & r ) {
gv_detail::convert(r,*this);
return *this;
}
// ======== Components ==============
/**
Set the axis and then the angle given a pair of pointers or iterators
defining the beginning and end of an array of four Scalars.
Precondition: The first three components are assumed to represent
the rotation axis vector and the 4-th the rotation angle.
The angle is assumed to be in the range (-pi,pi].
The axis vector is automatically normalized to be a unit vector
*/
template<class IT>
void SetComponents(IT begin, IT end) {
(void)end;
IT a = begin; IT b = ++begin; IT c = ++begin;
fAxis.SetCoordinates(*a,*b,*c);
fAngle = *(++begin);
assert (++begin==end);
// re-normalize the vector
double tot = fAxis.R();
if (tot > 0) fAxis /= tot;
}
/**
Get the axis and then the angle into data specified by an iterator begin
and another to the end of the desired data (4 past start).
*/
template<class IT>
void GetComponents(IT begin, IT end) const {
(void)end;
IT a = begin; IT b = ++begin; IT c = ++begin;
fAxis.GetCoordinates(*a,*b,*c);
*(++begin) = fAngle;
assert (++begin==end);
}
/**
Get the axis and then the angle into data specified by an iterator begin
*/
template<class IT>
void GetComponents(IT begin) const {
double ax,ay,az = 0;
fAxis.GetCoordinates(ax,ay,az);
*begin++ = ax;
*begin++ = ay;
*begin++ = az;
*begin = fAngle;
}
/**
Set components from a non-zero vector (x,y,z) and an angle.
Precondition: the Vector needs to implement x(), y(), z(), and unit()
*/
template<class AnyVector>
void SetComponents(const AnyVector & v, Scalar angle) {
fAxis=v.unit();
fAngle=angle;
}
/**
Set components into a non-zero vector (x,y,z) and an angle.
The vector is intended to be a cartesian dispalcement vector
but any vector class assignable from one will work.
*/
template<class AnyVector>
void GetComponents(AnyVector & axis, Scalar & angle) const {
axis = fAxis;
angle = fAngle;
}
/**
accesss to rotation axis
*/
AxisVector Axis() const { return fAxis; }
/**
access to rotation angle
*/
Scalar Angle() const { return fAngle; }
// =========== operations ==============
/**
Rotation operation on a cartesian vector
*/
typedef DisplacementVector3D<Cartesian3D<double>, DefaultCoordinateSystemTag > XYZVector;
XYZVector operator() (const XYZVector & v) const;
/**
Rotation operation on a displacement vector in any coordinate system
*/
template <class CoordSystem, class Tag>
DisplacementVector3D<CoordSystem, Tag>
operator() (const DisplacementVector3D<CoordSystem, Tag> & v) const {
DisplacementVector3D< Cartesian3D<double> > xyz(v.X(), v.Y(), v.Z());
DisplacementVector3D< Cartesian3D<double> > rxyz = operator()(xyz);
DisplacementVector3D< CoordSystem, Tag > vNew;
vNew.SetXYZ( rxyz.X(), rxyz.Y(), rxyz.Z() );
return vNew;
}
/**
Rotation operation on a position vector in any coordinate system
*/
template <class CoordSystem, class Tag>
PositionVector3D<CoordSystem, Tag>
operator() (const PositionVector3D<CoordSystem,Tag> & p) const {
DisplacementVector3D< Cartesian3D<double>,Tag > xyz(p);
DisplacementVector3D< Cartesian3D<double>,Tag > rxyz = operator()(xyz);
return PositionVector3D<CoordSystem,Tag> ( rxyz );
}
/**
Rotation operation on a Lorentz vector in any 4D coordinate system
*/
template <class CoordSystem>
LorentzVector<CoordSystem>
operator() (const LorentzVector<CoordSystem> & v) const {
DisplacementVector3D< Cartesian3D<double> > xyz(v.Vect());
xyz = operator()(xyz);
LorentzVector< PxPyPzE4D<double> > xyzt (xyz.X(), xyz.Y(), xyz.Z(), v.E());
return LorentzVector<CoordSystem> ( xyzt );
}
/**
Rotation operation on an arbitrary vector v.
Preconditions: v must implement methods x(), y(), and z()
and the arbitrary vector type must have a constructor taking (x,y,z)
*/
template <class ForeignVector>
ForeignVector
operator() (const ForeignVector & v) const {
DisplacementVector3D< Cartesian3D<double> > xyz(v);
DisplacementVector3D< Cartesian3D<double> > rxyz = operator()(xyz);
return ForeignVector ( rxyz.X(), rxyz.Y(), rxyz.Z() );
}
/**
Overload operator * for rotation on a vector
*/
template <class AVector>
inline
AVector operator* (const AVector & v) const
{
return operator()(v);
}
/**
Invert an AxisAngle rotation in place
*/
void Invert() { fAngle = -fAngle; }
/**
Return inverse of an AxisAngle rotation
*/
AxisAngle Inverse() const { AxisAngle result(*this); result.Invert(); return result; }
// ========= Multi-Rotation Operations ===============
/**
Multiply (combine) two rotations
*/
AxisAngle operator * (const Rotation3D & r) const;
AxisAngle operator * (const AxisAngle & a) const;
AxisAngle operator * (const EulerAngles & e) const;
AxisAngle operator * (const Quaternion & q) const;
AxisAngle operator * (const RotationZYX & r) const;
AxisAngle operator * (const RotationX & rx) const;
AxisAngle operator * (const RotationY & ry) const;
AxisAngle operator * (const RotationZ & rz) const;
/**
Post-Multiply (on right) by another rotation : T = T*R
*/
template <class R>
AxisAngle & operator *= (const R & r) { return *this = (*this)*r; }
/**
Distance between two rotations
*/
template <class R>
Scalar Distance ( const R & r ) const {return gv_detail::dist(*this,r);}
/**
Equality/inequality operators
*/
bool operator == (const AxisAngle & rhs) const {
if( fAxis != rhs.fAxis ) return false;
if( fAngle != rhs.fAngle ) return false;
return true;
}
bool operator != (const AxisAngle & rhs) const {
return ! operator==(rhs);
}
private:
AxisVector fAxis; // rotation axis (3D vector)
Scalar fAngle; // rotation angle
void RectifyAngle();
static double Pi() { return 3.14159265358979323; }
}; // AxisAngle
// ============ Class AxisAngle ends here ============
/**
Distance between two rotations
*/
template <class R>
inline
typename AxisAngle::Scalar
Distance ( const AxisAngle& r1, const R & r2) {return gv_detail::dist(r1,r2);}
/**
Multiplication of an axial rotation by an AxisAngle
*/
AxisAngle operator* (RotationX const & r1, AxisAngle const & r2);
AxisAngle operator* (RotationY const & r1, AxisAngle const & r2);
AxisAngle operator* (RotationZ const & r1, AxisAngle const & r2);
/**
Stream Output and Input
*/
// TODO - I/O should be put in the manipulator form
std::ostream & operator<< (std::ostream & os, const AxisAngle & a);
} // namespace Math
} // namespace ROOT
#endif /* ROOT_Math_GenVector_AxisAngle */
|