Jpp
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 double precision=std::numeric_limits< double >::min()) const
 Check equality. More...
 
double getDot (const JAngle3D &angle) const
 Get dot product. More...
 
JAngle3Dnormalise ()
 Normalise angles. More...
 
JAngle3Dmul (const JSecond_t &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 31 of file JAngle3D.hh.

Constructor & Destructor Documentation

◆ JAngle3D() [1/3]

JGEOMETRY3D::JAngle3D::JAngle3D ( )
inline

Default constructor.

Definition at line 38 of file JAngle3D.hh.

38  :
39  __theta(0.0),
40  __phi (0.0)
41  {}

◆ JAngle3D() [2/3]

JGEOMETRY3D::JAngle3D::JAngle3D ( const double  theta,
const double  phi 
)
inline

Constructor.

Parameters
thetatheta angle [rad]
phiphi angle [rad]

Definition at line 50 of file JAngle3D.hh.

51  :
52  __theta(theta),
53  __phi (phi)
54  {}

◆ JAngle3D() [3/3]

JGEOMETRY3D::JAngle3D::JAngle3D ( const double  x,
const double  y,
const double  z 
)
inline

Constructor.

Parameters
xx value
yy value
zz value

Definition at line 64 of file JAngle3D.hh.

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

Member Function Documentation

◆ getTheta()

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

Get theta angle.

Returns
theta angle

Definition at line 84 of file JAngle3D.hh.

85  {
86  return __theta;
87  }

◆ getPhi()

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

Get phi angle.

Returns
phi angle

Definition at line 95 of file JAngle3D.hh.

96  {
97  return __phi;
98  }

◆ getDX()

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

Get x direction.

Returns
x direction

Definition at line 106 of file JAngle3D.hh.

107  {
108  return sin(__theta) * cos(__phi);
109  }

◆ getDY()

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

Get y direction.

Returns
y direction

Definition at line 117 of file JAngle3D.hh.

118  {
119  return sin(__theta) * sin(__phi);
120  }

◆ getDZ()

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

Get z direction.

Returns
z direction

Definition at line 128 of file JAngle3D.hh.

129  {
130  return cos(__theta);
131  }

◆ negate()

JAngle3D& JGEOMETRY3D::JAngle3D::negate ( )
inline

Negate angle.

Returns
this angle

Definition at line 139 of file JAngle3D.hh.

140  {
141  __theta = -__theta;
142  __phi = -__phi;
143 
144  return *this;
145  }

◆ add()

JAngle3D& JGEOMETRY3D::JAngle3D::add ( const JAngle3D angle)
inline

Add angle.

Parameters
angleangle
Returns
this angle

Definition at line 154 of file JAngle3D.hh.

155  {
156  __theta += angle.getTheta();
157  __phi += angle.getPhi();
158 
159  return *this;
160  }

◆ sub()

JAngle3D& JGEOMETRY3D::JAngle3D::sub ( const JAngle3D angle)
inline

Subtract angle.

Parameters
angleangle
Returns
this angle

Definition at line 169 of file JAngle3D.hh.

170  {
171  __theta -= angle.getTheta();
172  __phi -= angle.getPhi();
173 
174  return *this;
175  }

◆ mul() [1/2]

JAngle3D& JGEOMETRY3D::JAngle3D::mul ( const double  factor)
inline

Scale angle.

Parameters
factormultiplication factor
Returns
this angle

Definition at line 183 of file JAngle3D.hh.

184  {
185  __theta *= factor;
186  __phi *= factor;
187 
188  return *this;
189  }

◆ div()

JAngle3D& JGEOMETRY3D::JAngle3D::div ( const double  factor)
inline

Scale angle.

Parameters
factordivision factor
Returns
this angle

Definition at line 198 of file JAngle3D.hh.

199  {
200  __theta /= factor;
201  __phi /= factor;
202 
203  return *this;
204  }

◆ equals()

bool JGEOMETRY3D::JAngle3D::equals ( const JAngle3D angle,
const double  precision = std::numeric_limits<double>::min() 
) const
inline

Check equality.

Parameters
angleangle
Returns
true if angles are equal; else false

Definition at line 213 of file JAngle3D.hh.

215  {
216  return (fabs(getTheta() - angle.getTheta()) <= precision &&
217  fabs(getPhi() - angle.getPhi()) <= precision);
218  }

◆ getDot()

double JGEOMETRY3D::JAngle3D::getDot ( const JAngle3D angle) const
inline

Get dot product.

Parameters
angleangle
Returns
dot product

Definition at line 227 of file JAngle3D.hh.

228  {
229  return
230  cos(getTheta()) * cos(angle.getTheta()) +
231  sin(getTheta()) * sin(angle.getTheta()) *
232  cos(getPhi() - angle.getPhi());
233  }

◆ normalise()

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 244 of file JAngle3D.hh.

245  {
246  using JTOOLS::PI;
247 
248  if (__theta > PI) { do { __theta -= PI; } while (__theta > PI); }
249  if (__theta < 0.0) { do { __theta += PI; } while (__theta < 0.0); }
250 
251  if (__phi > +PI) { do { __phi -= 2*PI; } while (__phi > +PI); }
252  if (__phi < -PI) { do { __phi += 2*PI; } while (__phi < -PI); }
253 
254  return *this;
255  }

◆ mul() [2/2]

JAngle3D & JMATH::JMath< JAngle3D , JSecond_t >::mul ( const JSecond_t &  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  }

Friends And Related Function Documentation

◆ operator>> [1/2]

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

Write angle from input.

Parameters
ininput stream
angleangle
Returns
input stream

Definition at line 265 of file JAngle3D.hh.

266  {
267  in >> angle.__theta >> angle.__phi;
268 
269  return in;
270  }

◆ operator<< [1/2]

std::ostream& operator<< ( std::ostream &  out,
const JAngle3D angle 
)
friend

Write angle to output.

Parameters
outoutput stream
angleangle
Returns
output stream

Definition at line 280 of file JAngle3D.hh.

281  {
282  out << angle.getTheta() << ' ' << angle.getPhi();
283 
284  return out;
285  }

◆ operator>> [2/2]

JReader& operator>> ( JReader in,
JAngle3D angle 
)
friend

Read angle from input.

Parameters
inreader
angleangle
Returns
reader

Definition at line 295 of file JAngle3D.hh.

296  {
297  in >> angle.__theta;
298  in >> angle.__phi;
299 
300  return in;
301  }

◆ operator<< [2/2]

JWriter& operator<< ( JWriter out,
const JAngle3D angle 
)
friend

Write angle to output.

Parameters
outwriter
angleangle
Returns
writer

Definition at line 311 of file JAngle3D.hh.

312  {
313  out << angle.getTheta();
314  out << angle.getPhi();
315 
316  return out;
317  }

Member Data Documentation

◆ __theta

double JGEOMETRY3D::JAngle3D::__theta
protected

Definition at line 320 of file JAngle3D.hh.

◆ __phi

double JGEOMETRY3D::JAngle3D::__phi
protected

Definition at line 321 of file JAngle3D.hh.


The documentation for this class was generated from the following file:
JGEOMETRY3D::JAngle3D::getPhi
double getPhi() const
Get phi angle.
Definition: JAngle3D.hh:95
JGEOMETRY3D::JAngle3D::getTheta
double getTheta() const
Get theta angle.
Definition: JAngle3D.hh:84
JTOOLS::v
data_type v[N+1][M+1]
Definition: JPolint.hh:707
JGEOMETRY3D::JAngle3D::__phi
double __phi
Definition: JAngle3D.hh:321
JTOOLS::PI
static const double PI
Constants.
Definition: JConstants.hh:20
JMATH::JCalculator
Auxiliary class for arithmetic operations on objects.
Definition: JCalculator.hh:18
JGEOMETRY3D::JAngle3D::__theta
double __theta
Definition: JAngle3D.hh:320