Jpp
JGeometry3DTestkit.hh
Go to the documentation of this file.
1 #ifndef __JGEOMETRY3DTESTKIT__
2 #define __JGEOMETRY3DTESTKIT__
3 
4 #include "TRandom3.h"
5 
6 #include "JTools/JConstants.hh"
12 #include "JGeometry3D/JSphere3D.hh"
14 #include "JMath/JRandom.hh"
15 
16 /**
17  * \author mdejong
18  */
19 
20 namespace JGEOMETRY3D {}
21 namespace JPP { using namespace JGEOMETRY3D; }
22 
23 namespace JGEOMETRY3D {
24 
25  using JTOOLS::PI;
26  using JMATH::getRandom;
27 
28 
29  /**
30  * Randomize position.
31  *
32  * \param p pointer to valid object
33  */
34  inline void randomize(JPosition3D* p)
35  {
36  new (p) JPosition3D(getRandom<double>(-1.0, +1.0),
37  getRandom<double>(-1.0, +1.0),
38  getRandom<double>(-1.0, +1.0));
39  };
40 
41 
42  /**
43  * Randomize direction.
44  *
45  * \param p pointer to valid object
46  */
47  inline void randomize(JDirection3D* p)
48  {
49  double x, y, z;
50 
51  gRandom->Sphere(x, y, z, 1.0);
52 
53  new (p) JDirection3D(x, y, z);
54  };
55 
56 
57  /**
58  * Randomize quaternion.
59  *
60  * \param p pointer to valid object
61  */
62  inline void randomize(JQuaternion3D* p)
63  {
64  double x, y, z;
65 
66  gRandom->Sphere(x, y, z, 1.0);
67 
68  const double alpha = getRandom<double>(-PI, +PI);
69 
70  new (p) JQuaternion3D(alpha, JVersor3D(x, y, z));
71  }
72 
73 
74  /**
75  * Randomize Euler angle.
76  *
77  * \param p pointer to valid object
78  */
79  inline void randomize(JEulerAngle3D* p)
80  {
81  new (p) JEulerAngle3D(getRandom<double>(0.0, PI),
82  getRandom<double>(0.0, PI),
83  getRandom<double>(0.0, PI));
84  }
85 
86 
87  /**
88  * Randomize Euler matrix.
89  *
90  * \param p pointer to valid object
91  */
92  inline void randomize(JEulerMatrix3D* p)
93  {
94  new (p) JEulerMatrix3D(getRandom<JEulerAngle3D>());
95  }
96 
97 
98  /**
99  * Get random position.\n
100  * The positions are uniformly distributed in given sphere.
101  *
102  * \param sphere sphere
103  * \return position
104  */
105  inline JVector3D getRandomPosition(const JSphere3D& sphere)
106  {
107  const double R3max = sphere.getRadius() * sphere.getRadius() * sphere.getRadius();
108 
109  const double R3 = gRandom->Uniform(0.0, R3max);
110  const double ct = gRandom->Uniform(-1.0, +1.0);
111  const double phi = gRandom->Uniform(-PI, +PI);
112 
113  const double R = cbrt(R3);
114  const double st = sqrt((1.0 + ct) * (1.0 - ct));
115 
116  return sphere.getPosition() + JVector3D(R * st * cos(phi),
117  R * st * sin(phi),
118  R * ct);
119  }
120 
121 
122  /**
123  * Get random position.\n
124  * The positions are uniformly distributed in given cylinder.
125  *
126  * \param cylinder cylinder
127  * \return position
128  */
129  inline JVector3D getRandomPosition(const JCylinder3D& cylinder)
130  {
131  const double R2max = cylinder.getRadius() * cylinder.getRadius();
132 
133  const double R2 = gRandom->Uniform(0.0, R2max);
134  const double phi = gRandom->Uniform(-PI, +PI);
135  const double z = gRandom->Uniform(cylinder.getZmin(), cylinder.getZmax());
136 
137  const double R = sqrt(R2);
138 
139  return JVector3D(cylinder.getX() + R * cos(phi),
140  cylinder.getY() + R * sin(phi),
141  z);
142  }
143 }
144 
145 #endif
JPosition3D.hh
JDirection3D.hh
JGEOMETRY3D::JCylinder3D::getZmin
double getZmin() const
Get minimal z position.
Definition: JCylinder3D.hh:101
JGEOMETRY3D::JSphere3D::getRadius
double getRadius() const
Get radius.
Definition: JSphere3D.hh:58
JGEOMETRY3D::JDirection3D
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:32
JQuaternion3D.hh
JGEOMETRY3D::JVersor3D
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:23
JGEOMETRY2D::JCircle2D::getRadius
double getRadius() const
Get radius.
Definition: JCircle2D.hh:121
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JGEOMETRY3D::JCylinder3D
Cylinder object.
Definition: JCylinder3D.hh:37
JGEOMETRY3D::JVector3D
Data structure for vector in three dimensions.
Definition: JVector3D.hh:33
JConstants.hh
JGEOMETRY3D::JPosition3D
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
JGEOMETRY3D::getRandomPosition
JVector3D getRandomPosition(const JCylinder3D &cylinder)
Get random position.
Definition: JGeometry3DTestkit.hh:129
JGEOMETRY3D::JQuaternion3D
Data structure for quaternion in three dimensions.
Definition: JQuaternion3D.hh:240
JEulerMatrix3D.hh
JGEOMETRY3D::randomize
void randomize(JEulerMatrix3D *p)
Randomize Euler matrix.
Definition: JGeometry3DTestkit.hh:92
JSphere3D.hh
JGEOMETRY3D::JPosition3D::getPosition
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
JGEOMETRY3D::JCylinder3D::getZmax
double getZmax() const
Get maximal z position.
Definition: JCylinder3D.hh:112
JRotation3D.hh
JCylinder3D.hh
JTOOLS::PI
static const double PI
Constants.
Definition: JConstants.hh:20
JGEOMETRY2D::JVector2D::getX
double getX() const
Get x position.
Definition: JVector2D.hh:62
JGEOMETRY3D
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition: JAngle3D.hh:18
JGEOMETRY3D::JSphere3D
3D sphere.
Definition: JSphere3D.hh:27
JGEOMETRY2D::JVector2D::getY
double getY() const
Get y position.
Definition: JVector2D.hh:73
JGEOMETRY3D::JEulerAngle3D
Data structure for Euler angles in three dimensions.
Definition: JEulerAngle3D.hh:34
JRandom.hh
JGEOMETRY3D::JEulerMatrix3D
Euler matrix.
Definition: JEulerMatrix3D.hh:32
JMATH::getRandom
T getRandom()
Get random value.
Definition: JRandom.hh:113