Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | Friends | List of all members
JGEOMETRY3D::JAngle3D Class Reference

Data structure for angles in three dimensions. More...

#include <JAngle3D.hh>

Inheritance diagram for JGEOMETRY3D::JAngle3D:
JMATH::JMath< JAngle3D >

Public Member Functions

 JAngle3D ()
 Default constructor. More...
 
 JAngle3D (const double theta, const double phi)
 Constructor. More...
 
 JAngle3D (const double x, const double y, const double z)
 Constructor. More...
 
double getTheta () const
 Get theta angle. More...
 
double getPhi () const
 Get phi angle. More...
 
double getDX () const
 Get x direction. More...
 
double getDY () const
 Get y direction. More...
 
double getDZ () const
 Get z direction. More...
 
JAngle3Dnegate ()
 Negate angle. More...
 
JAngle3Dadd (const JAngle3D &angle)
 Add angle. More...
 
JAngle3Dsub (const JAngle3D &angle)
 Subtract angle. More...
 
JAngle3Dmul (const double factor)
 Scale angle. More...
 
JAngle3Ddiv (const double factor)
 Scale angle. More...
 
bool equals (const JAngle3D &angle) const
 Check equality. More...
 
double getDot (const JAngle3D &angle) const
 Get dot product. More...
 
JAngle3Dnormalise ()
 Normalise angles. More...
 
JAngle3Dmul (const JNullType &object)
 Multiply with object. More...
 

Protected Attributes

double __theta
 
double __phi
 

Friends

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

Detailed Description

Data structure for angles in three dimensions.

This class serves as input to the rotation matrix JRotation3D.

Definition at line 30 of file JAngle3D.hh.

Constructor & Destructor Documentation

JGEOMETRY3D::JAngle3D::JAngle3D ( )
inline

Default constructor.

Definition at line 37 of file JAngle3D.hh.

37  :
38  __theta(0.0),
39  __phi (0.0)
40  {}
JGEOMETRY3D::JAngle3D::JAngle3D ( const double  theta,
const double  phi 
)
inline

Constructor.

Parameters
thetatheta angle [rad]
phiphi angle [rad]

Definition at line 49 of file JAngle3D.hh.

50  :
51  __theta(theta),
52  __phi (phi)
53  {}
JGEOMETRY3D::JAngle3D::JAngle3D ( const double  x,
const double  y,
const double  z 
)
inline

Constructor.

Parameters
xx value
yy value
zz value

Definition at line 63 of file JAngle3D.hh.

65  :
66  __theta(0.0),
67  __phi (0.0)
68  {
69  const double v = x*x + y*y + z*z;
70 
71  if (v != 0.0) {
72  __theta = acos (z / sqrt(v));
73  __phi = atan2(y, x);
74  }
75  }

Member Function Documentation

double JGEOMETRY3D::JAngle3D::getTheta ( ) const
inline

Get theta angle.

Returns
theta angle

Definition at line 83 of file JAngle3D.hh.

84  {
85  return __theta;
86  }
double JGEOMETRY3D::JAngle3D::getPhi ( ) const
inline

Get phi angle.

Returns
phi angle

Definition at line 94 of file JAngle3D.hh.

95  {
96  return __phi;
97  }
double JGEOMETRY3D::JAngle3D::getDX ( ) const
inline

Get x direction.

Returns
x direction

Definition at line 105 of file JAngle3D.hh.

106  {
107  return sin(__theta) * cos(__phi);
108  }
double JGEOMETRY3D::JAngle3D::getDY ( ) const
inline

Get y direction.

Returns
y direction

Definition at line 116 of file JAngle3D.hh.

117  {
118  return sin(__theta) * sin(__phi);
119  }
double JGEOMETRY3D::JAngle3D::getDZ ( ) const
inline

Get z direction.

Returns
z direction

Definition at line 127 of file JAngle3D.hh.

128  {
129  return cos(__theta);
130  }
JAngle3D& JGEOMETRY3D::JAngle3D::negate ( )
inline

Negate angle.

Returns
this angle

Definition at line 138 of file JAngle3D.hh.

139  {
140  __theta = -__theta;
141  __phi = -__phi;
142 
143  return *this;
144  }
JAngle3D& JGEOMETRY3D::JAngle3D::add ( const JAngle3D angle)
inline

Add angle.

Parameters
angleangle
Returns
this angle

Definition at line 153 of file JAngle3D.hh.

154  {
155  __theta += angle.getTheta();
156  __phi += angle.getPhi();
157 
158  return *this;
159  }
double getPhi() const
Get phi angle.
Definition: JAngle3D.hh:94
double getTheta() const
Get theta angle.
Definition: JAngle3D.hh:83
JAngle3D& JGEOMETRY3D::JAngle3D::sub ( const JAngle3D angle)
inline

Subtract angle.

Parameters
angleangle
Returns
this angle

Definition at line 168 of file JAngle3D.hh.

169  {
170  __theta -= angle.getTheta();
171  __phi -= angle.getPhi();
172 
173  return *this;
174  }
double getPhi() const
Get phi angle.
Definition: JAngle3D.hh:94
double getTheta() const
Get theta angle.
Definition: JAngle3D.hh:83
JAngle3D& JGEOMETRY3D::JAngle3D::mul ( const double  factor)
inline

Scale angle.

Parameters
factormultiplication factor
Returns
this angle

Definition at line 182 of file JAngle3D.hh.

183  {
184  __theta *= factor;
185  __phi *= factor;
186 
187  return *this;
188  }
JAngle3D& JGEOMETRY3D::JAngle3D::div ( const double  factor)
inline

Scale angle.

Parameters
factordivision factor
Returns
this angle

Definition at line 197 of file JAngle3D.hh.

198  {
199  __theta /= factor;
200  __phi /= factor;
201 
202  return *this;
203  }
bool JGEOMETRY3D::JAngle3D::equals ( const JAngle3D angle) const
inline

Check equality.

Parameters
angleangle
Returns
true if angles are equal; else false

Definition at line 212 of file JAngle3D.hh.

213  {
214  return (getTheta() == angle.getTheta() &&
215  getPhi() == angle.getPhi());
216  }
double getPhi() const
Get phi angle.
Definition: JAngle3D.hh:94
double getTheta() const
Get theta angle.
Definition: JAngle3D.hh:83
double JGEOMETRY3D::JAngle3D::getDot ( const JAngle3D angle) const
inline

Get dot product.

Parameters
angleangle
Returns
dot product

Definition at line 225 of file JAngle3D.hh.

226  {
227  return
228  cos(getTheta()) * cos(angle.getTheta()) +
229  sin(getTheta()) * sin(angle.getTheta()) *
230  cos(getPhi() - angle.getPhi());
231  }
double getPhi() const
Get phi angle.
Definition: JAngle3D.hh:94
double getTheta() const
Get theta angle.
Definition: JAngle3D.hh:83
JAngle3D& JGEOMETRY3D::JAngle3D::normalise ( )
inline

Normalise angles.

  • theta angle will be between 0 and π
  • phi angle will be between -π and +π
Returns
this angle

Definition at line 242 of file JAngle3D.hh.

243  {
244  using JTOOLS::PI;
245 
246  if (__theta > PI) { do { __theta -= PI; } while (__theta > PI); }
247  if (__theta < 0.0) { do { __theta += PI; } while (__theta < 0.0); }
248 
249  if (__phi > +PI) { do { __phi -= 2*PI; } while (__phi > +PI); }
250  if (__phi < -PI) { do { __phi += 2*PI; } while (__phi < -PI); }
251 
252  return *this;
253  }
static const double PI
Constants.
Definition: JConstants.hh:20
JAngle3D & JMATH::JMath< JAngle3D , JNullType >::mul ( const JNullType object)
inlineinherited

Multiply with object.

Parameters
objectobject
Returns
result object

Definition at line 273 of file JMath.hh.

274  {
275  return static_cast<JFirst_t&>(*this) = JCalculator<JFirst_t>::calculator.mul(static_cast<const JFirst_t&>(*this), object);
276  }
Auxiliary class for product evaluation of objects.
Definition: JCalculator.hh:18

Friends And Related Function Documentation

std::istream& operator>> ( std::istream &  in,
JAngle3D angle 
)
friend

Write angle from input.

Parameters
ininput stream
angleangle
Returns
input stream

Definition at line 263 of file JAngle3D.hh.

264  {
265  in >> angle.__theta >> angle.__phi;
266 
267  return in;
268  }
std::ostream& operator<< ( std::ostream &  out,
const JAngle3D angle 
)
friend

Write angle to output.

Parameters
outoutput stream
angleangle
Returns
output stream

Definition at line 278 of file JAngle3D.hh.

279  {
280  out << angle.getTheta() << ' ' << angle.getPhi();
281 
282  return out;
283  }
double getPhi() const
Get phi angle.
Definition: JAngle3D.hh:94
double getTheta() const
Get theta angle.
Definition: JAngle3D.hh:83
JReader& operator>> ( JReader in,
JAngle3D angle 
)
friend

Read angle from input.

Parameters
inreader
angleangle
Returns
reader

Definition at line 293 of file JAngle3D.hh.

294  {
295  in >> angle.__theta;
296  in >> angle.__phi;
297 
298  return in;
299  }
JWriter& operator<< ( JWriter out,
const JAngle3D angle 
)
friend

Write angle to output.

Parameters
outwriter
angleangle
Returns
writer

Definition at line 309 of file JAngle3D.hh.

310  {
311  out << angle.getTheta();
312  out << angle.getPhi();
313 
314  return out;
315  }
double getPhi() const
Get phi angle.
Definition: JAngle3D.hh:94
double getTheta() const
Get theta angle.
Definition: JAngle3D.hh:83

Member Data Documentation

double JGEOMETRY3D::JAngle3D::__theta
protected

Definition at line 318 of file JAngle3D.hh.

double JGEOMETRY3D::JAngle3D::__phi
protected

Definition at line 319 of file JAngle3D.hh.


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