Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JGEOMETRY3D::JAngle3D Class Reference

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

#include <JAngle3D.hh>

Inheritance diagram for JGEOMETRY3D::JAngle3D:
JMATH::JMath< JFirst_t, JSecond_t >

Public Member Functions

 JAngle3D ()
 Default constructor.
 
 JAngle3D (const double theta, const double phi)
 Constructor.
 
 JAngle3D (const double x, const double y, const double z)
 Constructor.
 
double getTheta () const
 Get theta angle.
 
double getPhi () const
 Get phi angle.
 
double getDX () const
 Get x direction.
 
double getDY () const
 Get y direction.
 
double getDZ () const
 Get z direction.
 
JAngle3Dnegate ()
 Negate angle.
 
JAngle3Dadd (const JAngle3D &angle)
 Add angle.
 
JAngle3Dsub (const JAngle3D &angle)
 Subtract angle.
 
JAngle3Dmul (const double factor)
 Scale angle.
 
JAngle3Ddiv (const double factor)
 Scale angle.
 
bool equals (const JAngle3D &angle, const double precision=std::numeric_limits< double >::min()) const
 Check equality.
 
double getDot (const JAngle3D &angle) const
 Get dot product.
 
JAngle3Dnormalise ()
 Normalise angles.
 
JFirst_t & mul (const JSecond_t &object)
 Multiply with object.
 

Protected Attributes

double __theta
 
double __phi
 

Friends

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

Detailed Description

Data structure for angles in three dimensions.

This class serves as input to the rotation matrix JRotation3D.

Definition at line 33 of file JAngle3D.hh.

Constructor & Destructor Documentation

◆ JAngle3D() [1/3]

JGEOMETRY3D::JAngle3D::JAngle3D ( )
inline

Default constructor.

Definition at line 40 of file JAngle3D.hh.

40 :
41 __theta(0.0),
42 __phi (0.0)
43 {}

◆ JAngle3D() [2/3]

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

Constructor.

Parameters
thetatheta angle [rad]
phiphi angle [rad]

Definition at line 52 of file JAngle3D.hh.

53 :
54 __theta(theta),
55 __phi (phi)
56 {}

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

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

Member Function Documentation

◆ getTheta()

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

Get theta angle.

Returns
theta angle

Definition at line 86 of file JAngle3D.hh.

87 {
88 return __theta;
89 }

◆ getPhi()

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

Get phi angle.

Returns
phi angle

Definition at line 97 of file JAngle3D.hh.

98 {
99 return __phi;
100 }

◆ getDX()

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

Get x direction.

Returns
x direction

Definition at line 108 of file JAngle3D.hh.

109 {
110 return sin(__theta) * cos(__phi);
111 }

◆ getDY()

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

Get y direction.

Returns
y direction

Definition at line 119 of file JAngle3D.hh.

120 {
121 return sin(__theta) * sin(__phi);
122 }

◆ getDZ()

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

Get z direction.

Returns
z direction

Definition at line 130 of file JAngle3D.hh.

131 {
132 return cos(__theta);
133 }

◆ negate()

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

Negate angle.

Returns
this angle

Definition at line 141 of file JAngle3D.hh.

142 {
143 __theta = -__theta;
144 __phi = -__phi;
145
146 return *this;
147 }

◆ add()

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

Add angle.

Parameters
angleangle
Returns
this angle

Definition at line 156 of file JAngle3D.hh.

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

◆ sub()

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

Subtract angle.

Parameters
angleangle
Returns
this angle

Definition at line 171 of file JAngle3D.hh.

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

◆ mul() [1/2]

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

Scale angle.

Parameters
factormultiplication factor
Returns
this angle

Definition at line 185 of file JAngle3D.hh.

186 {
187 __theta *= factor;
188 __phi *= factor;
189
190 return *this;
191 }

◆ div()

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

Scale angle.

Parameters
factordivision factor
Returns
this angle

Definition at line 200 of file JAngle3D.hh.

201 {
202 __theta /= factor;
203 __phi /= factor;
204
205 return *this;
206 }

◆ equals()

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

Check equality.

Parameters
angleangle
precisionprecision
Returns
true if angles are equal; else false

Definition at line 216 of file JAngle3D.hh.

218 {
219 return (fabs(getTheta() - angle.getTheta()) <= precision &&
220 fabs(getPhi() - angle.getPhi()) <= precision);
221 }
double getTheta() const
Get theta angle.
Definition JAngle3D.hh:86
double getPhi() const
Get phi angle.
Definition JAngle3D.hh:97

◆ getDot()

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

Get dot product.

Parameters
angleangle
Returns
dot product

Definition at line 230 of file JAngle3D.hh.

231 {
232 return
233 cos(getTheta()) * cos(angle.getTheta()) +
234 sin(getTheta()) * sin(angle.getTheta()) *
235 cos(getPhi() - angle.getPhi());
236 }

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

248 {
249 using JMATH::PI;
250
251 if (__theta > PI) { do { __theta -= PI; } while (__theta > PI); }
252 if (__theta < 0.0) { do { __theta += PI; } while (__theta < 0.0); }
253
254 if (__phi > +PI) { do { __phi -= 2*PI; } while (__phi > +PI); }
255 if (__phi < -PI) { do { __phi += 2*PI; } while (__phi < -PI); }
256
257 return *this;
258 }
static const double PI
Mathematical constants.

◆ mul() [2/2]

template<class JFirst_t , class JSecond_t >
JFirst_t & JMATH::JMath< JFirst_t, JSecond_t >::mul ( const JSecond_t & object)
inlineinherited

Multiply with object.

Parameters
objectobject
Returns
result object

Definition at line 354 of file JMath.hh.

355 {
356 return static_cast<JFirst_t&>(*this) = JFirst_t().mul(static_cast<const JFirst_t&>(*this), object);
357 }

Friends And Related Symbol 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 268 of file JAngle3D.hh.

269 {
270 in >> angle.__theta >> angle.__phi;
271
272 return in;
273 }

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

284 {
285 const JFormat format(out, getFormat<JAngle3D>(JFormat_t(9, 5, std::ios::fixed | std::ios::showpos)));
286
287 out << format << angle.getTheta() << ' '
288 << format << angle.getPhi();
289
290 return out;
291 }
JFormat_t & getFormat()
Get format for given type.
Definition JManip.hh:682
Data structure for format specifications.
Definition JManip.hh:524
Auxiliary class to temporarily define format specifications.
Definition JManip.hh:636

◆ operator>> [2/2]

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

Read angle from input.

Parameters
inreader
angleangle
Returns
reader

Definition at line 301 of file JAngle3D.hh.

302 {
303 in >> angle.__theta;
304 in >> angle.__phi;
305
306 return in;
307 }

◆ operator<< [2/2]

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

Write angle to output.

Parameters
outwriter
angleangle
Returns
writer

Definition at line 317 of file JAngle3D.hh.

318 {
319 out << angle.__theta;
320 out << angle.__phi;
321
322 return out;
323 }

Member Data Documentation

◆ __theta

double JGEOMETRY3D::JAngle3D::__theta
protected

Definition at line 326 of file JAngle3D.hh.

◆ __phi

double JGEOMETRY3D::JAngle3D::__phi
protected

Definition at line 327 of file JAngle3D.hh.


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