Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JGEOMETRY2D::JDirection2D Class Reference

Data structure for direction in two dimensions. More...

#include <JDirection2D.hh>

Inheritance diagram for JGEOMETRY2D::JDirection2D:
JGEOMETRY2D::JVersor2D JGEOMETRY2D::JAxis2D

Public Member Functions

 JDirection2D ()
 Default constructor.
 
 JDirection2D (const JVersor2D &dir)
 Constructor.
 
 JDirection2D (const JAngle2D &angle)
 Constructor.
 
 JDirection2D (const JVector2D &pos)
 Constructor.
 
 JDirection2D (const double dx, const double dy)
 Constructor.
 
const JDirection2DgetDirection () const
 Get direction.
 
JDirection2DgetDirection ()
 Get direction.
 
void setDirection (const JDirection2D &dir)
 Set direction.
 
 operator JAngle2D () const
 Type conversion operator.
 
 operator JVector2D () const
 Type conversion operator.
 
JDirection2Dtransform (const JMatrix2D &T)
 Transform.
 
JDirection2Drotate (const JRotation2D &R)
 Rotate.
 
JDirection2Drotate_back (const JRotation2D &R)
 Rotate back.
 
double getDot (const JAngle2D &angle) const
 Get dot product.
 
double getDot (const JVector2D &pos) const
 Get dot product.
 
double getPerpDot (const JAngle2D &angle) const
 Get perpendicular dot product.
 
double getPerpDot (const JVector2D &pos) const
 Get perpendicular dot product.
 
double getDot (const JVersor2D &versor) const
 Get dot product.
 
double getPerpDot (const JVersor2D &versor) const
 Get perpendicular dot product.
 
double getDX () const
 Get x direction.
 
double getDY () const
 Get y direction.
 
double getPhi () const
 Get phi angle.
 
JVersor2Dnegate ()
 Negate versor.
 
bool equals (const JVersor2D &versor, const double precision=std::numeric_limits< double >::min()) const
 Check equality.
 
JVersor2Dnormalise ()
 Normalise versor.
 

Protected Attributes

double __dx
 
double __dy
 

Friends

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

Detailed Description

Data structure for direction in two dimensions.

Definition at line 31 of file JDirection2D.hh.

Constructor & Destructor Documentation

◆ JDirection2D() [1/5]

JGEOMETRY2D::JDirection2D::JDirection2D ( )
inline

Default constructor.

Definition at line 43 of file JDirection2D.hh.

43 :
44 JVersor2D()
45 {}
JVersor2D()
Default constructor.
Definition JVersor2D.hh:27

◆ JDirection2D() [2/5]

JGEOMETRY2D::JDirection2D::JDirection2D ( const JVersor2D & dir)
inline

Constructor.

Parameters
dirdirection

Definition at line 53 of file JDirection2D.hh.

53 :
54 JVersor2D(dir.getDY(), dir.getDX())
55 {}

◆ JDirection2D() [3/5]

JGEOMETRY2D::JDirection2D::JDirection2D ( const JAngle2D & angle)
inline

Constructor.

Parameters
angleangle

Definition at line 63 of file JDirection2D.hh.

63 :
64 JVersor2D(angle.getDX(), angle.getDY())
65 {}

◆ JDirection2D() [4/5]

JGEOMETRY2D::JDirection2D::JDirection2D ( const JVector2D & pos)
inline

Constructor.

Parameters
posposition

Definition at line 73 of file JDirection2D.hh.

73 :
74 JVersor2D(pos.getY(),pos.getX())
75 {}

◆ JDirection2D() [5/5]

JGEOMETRY2D::JDirection2D::JDirection2D ( const double dx,
const double dy )
inline

Constructor.

Parameters
dxdx value
dydy value

Definition at line 84 of file JDirection2D.hh.

85 :
86 JVersor2D(dx, dy)
87 {}

Member Function Documentation

◆ getDirection() [1/2]

const JDirection2D & JGEOMETRY2D::JDirection2D::getDirection ( ) const
inline

Get direction.

Returns
direction

Definition at line 95 of file JDirection2D.hh.

96 {
97 return static_cast<const JDirection2D&>(*this);
98 }
JDirection2D()
Default constructor.

◆ getDirection() [2/2]

JDirection2D & JGEOMETRY2D::JDirection2D::getDirection ( )
inline

Get direction.

Returns
direction

Definition at line 106 of file JDirection2D.hh.

107 {
108 return static_cast<JDirection2D&>(*this);
109 }

◆ setDirection()

void JGEOMETRY2D::JDirection2D::setDirection ( const JDirection2D & dir)
inline

Set direction.

Parameters
dirdirection

Definition at line 117 of file JDirection2D.hh.

118 {
119 static_cast<JDirection2D&>(*this) = dir;
120 }

◆ operator JAngle2D()

JGEOMETRY2D::JDirection2D::operator JAngle2D ( ) const
inline

Type conversion operator.

Returns
angle

Definition at line 128 of file JDirection2D.hh.

129 {
130 return JAngle2D(getDX(), getDY());
131 }
double getDX() const
Get x direction.
Definition JVersor2D.hh:53
double getDY() const
Get y direction.
Definition JVersor2D.hh:64

◆ operator JVector2D()

JGEOMETRY2D::JDirection2D::operator JVector2D ( ) const
inline

Type conversion operator.

Returns
position

Definition at line 139 of file JDirection2D.hh.

140 {
141 return JVector2D(getDX(), getDY());
142 }

◆ transform()

JDirection2D & JGEOMETRY2D::JDirection2D::transform ( const JMatrix2D & T)
inline

Transform.

Parameters
Tmatrix
Returns
this direction

Definition at line 151 of file JDirection2D.hh.

152 {
153 T.transform(__dx, __dy);
154
155 normalise();
156
157 return *this;
158 }
JVersor2D & normalise()
Normalise versor.
Definition JVersor2D.hh:144

◆ rotate()

JDirection2D & JGEOMETRY2D::JDirection2D::rotate ( const JRotation2D & R)
inline

Rotate.

Parameters
Rrotation matrix
Returns
this direction

Definition at line 167 of file JDirection2D.hh.

168 {
169 R.rotate(__dx, __dy);
170
171 normalise();
172
173 return *this;
174 }

◆ rotate_back()

JDirection2D & JGEOMETRY2D::JDirection2D::rotate_back ( const JRotation2D & R)
inline

Rotate back.

Parameters
Rrotation matrix
Returns
this direction

Definition at line 183 of file JDirection2D.hh.

184 {
185 R.rotate_back(__dx, __dy);
186
187 normalise();
188
189 return *this;
190 }

◆ getDot() [1/3]

double JGEOMETRY2D::JDirection2D::getDot ( const JAngle2D & angle) const
inline

Get dot product.

Parameters
angleangle
Returns
dot product

Definition at line 199 of file JDirection2D.hh.

200 {
201 return
202 getDX() * angle.getDX() +
203 getDY() * angle.getDY();
204 }

◆ getDot() [2/3]

double JGEOMETRY2D::JDirection2D::getDot ( const JVector2D & pos) const
inline

Get dot product.

Parameters
posposition
Returns
dot product

Definition at line 213 of file JDirection2D.hh.

214 {
215 return
216 getDX() * pos.getX() +
217 getDY() * pos.getY();
218 }

◆ getPerpDot() [1/3]

double JGEOMETRY2D::JDirection2D::getPerpDot ( const JAngle2D & angle) const
inline

Get perpendicular dot product.

Parameters
angleangle
Returns
perpendicular dot product

Definition at line 227 of file JDirection2D.hh.

228 {
229 return
230 getDX() * angle.getDY() -
231 getDY() * angle.getDX();
232 }

◆ getPerpDot() [2/3]

double JGEOMETRY2D::JDirection2D::getPerpDot ( const JVector2D & pos) const
inline

Get perpendicular dot product.

Parameters
posposition
Returns
perpendicular dot product

Definition at line 241 of file JDirection2D.hh.

242 {
243 return
244 getDX() * pos.getY() -
245 getDY() * pos.getX();
246 }

◆ getDot() [3/3]

double JGEOMETRY2D::JVersor2D::getDot ( const JVersor2D & versor) const
inline

Get dot product.

Parameters
versorversor
Returns
dot product

Definition at line 116 of file JVersor2D.hh.

117 {
118 return
119 getDX() * versor.getDX() +
120 getDY() * versor.getDY();
121 }

◆ getPerpDot() [3/3]

double JGEOMETRY2D::JVersor2D::getPerpDot ( const JVersor2D & versor) const
inline

Get perpendicular dot product.

Parameters
versorversor
Returns
perpendicular dot product

Definition at line 130 of file JVersor2D.hh.

131 {
132 return
133 getDX() * versor.getDY() -
134 getDY() * versor.getDX();
135 }

◆ getDX()

double JGEOMETRY2D::JVersor2D::getDX ( ) const
inlineinherited

Get x direction.

Returns
x direction

Definition at line 53 of file JVersor2D.hh.

54 {
55 return __dx;
56 }

◆ getDY()

double JGEOMETRY2D::JVersor2D::getDY ( ) const
inlineinherited

Get y direction.

Returns
y direction

Definition at line 64 of file JVersor2D.hh.

65 {
66 return __dy;
67 }

◆ getPhi()

double JGEOMETRY2D::JVersor2D::getPhi ( ) const
inlineinherited

Get phi angle.

Returns
phi angle [rad]

Definition at line 75 of file JVersor2D.hh.

76 {
77 return atan2(__dy, __dx);
78 }

◆ negate()

JVersor2D & JGEOMETRY2D::JVersor2D::negate ( )
inlineinherited

Negate versor.

Returns
this versor

Definition at line 86 of file JVersor2D.hh.

87 {
88 __dx = -__dx;
89 __dy = -__dy;
90
91 return *this;
92 }

◆ equals()

bool JGEOMETRY2D::JVersor2D::equals ( const JVersor2D & versor,
const double precision = std::numeric_limits<double>::min() ) const
inlineinherited

Check equality.

Parameters
versorversor
precisionprecision
Returns
true if versors are equal; else false

Definition at line 102 of file JVersor2D.hh.

104 {
105 return (fabs(getDX() - versor.getDX()) <= precision &&
106 fabs(getDY() - versor.getDY()) <= precision);
107 }

◆ normalise()

JVersor2D & JGEOMETRY2D::JVersor2D::normalise ( )
inlineinherited

Normalise versor.

This operation may set the result to the unit y-vector.

Returns
this versor

Definition at line 144 of file JVersor2D.hh.

145 {
146 const double v = sqrt(getDX()*getDX() + getDY()*getDY());
147
148 if (v != 0.0) {
149 __dx /= v;
150 __dy /= v;
151 } else {
152 __dx = 0.0;
153 __dy = 1.0;
154 }
155
156 return *this;
157 }

Friends And Related Symbol Documentation

◆ operator>> [1/2]

std::istream & operator>> ( std::istream & in,
JDirection2D & direction )
friend

Read direction from input.

Parameters
ininput stream
directiondirection
Returns
input stream

Definition at line 256 of file JDirection2D.hh.

257 {
258 in >> direction.__dx >> direction.__dy;
259
260 direction.normalise();
261
262 return in;
263 }

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream & out,
const JDirection2D & direction )
friend

Write direction to output.

Parameters
outoutput stream
directiondirection
Returns
output stream

Definition at line 273 of file JDirection2D.hh.

274 {
275 const JFormat format(out, getFormat<JDirection2D>(JFormat_t(9, 6, std::ios::fixed | std::ios::showpos)));
276
277 out << format << direction.getDX() << ' '
278 << format << direction.getDY();
279
280 return out;
281 }
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,
JDirection2D & direction )
friend

Read direction from input.

Parameters
inreader
directiondirection
Returns
reader

Definition at line 291 of file JDirection2D.hh.

292 {
293 in >> direction.__dx;
294 in >> direction.__dy;
295
296 return in;
297 }

◆ operator<< [2/2]

JWriter & operator<< ( JWriter & out,
const JDirection2D & direction )
friend

Write direction to output.

Parameters
outwriter
directiondirection
Returns
writer

Definition at line 307 of file JDirection2D.hh.

308 {
309 out << direction.__dx;
310 out << direction.__dy;
311
312 return out;
313 }

Member Data Documentation

◆ __dx

double JGEOMETRY2D::JVersor2D::__dx
protectedinherited

Definition at line 160 of file JVersor2D.hh.

◆ __dy

double JGEOMETRY2D::JVersor2D::__dy
protectedinherited

Definition at line 161 of file JVersor2D.hh.


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