Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JGeometry3DTestkit.hh
Go to the documentation of this file.
1 #ifndef __JGEOMETRY3DTESTKIT__
2 #define __JGEOMETRY3DTESTKIT__
3 
4 #include "TRandom3.h"
5 
11 #include "JGeometry3D/JSphere3D.hh"
13 #include "JMath/JRandom.hh"
14 #include "JMath/JConstants.hh"
15 
16 /**
17  * \author mdejong
18  */
19 
20 namespace JGEOMETRY3D {}
21 namespace JPP { using namespace JGEOMETRY3D; }
22 
23 namespace JGEOMETRY3D {
24 
25  using JMATH::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>(-2.0*PI, +2.0*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
Data structure for Euler angles in three dimensions.
double getRadius() const
Get radius.
Definition: JCircle2D.hh:144
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:33
double getZmin() const
Get minimal z position.
Definition: JCylinder3D.hh:111
Definition of random value generator.
double getY() const
Get y position.
Definition: JVector2D.hh:74
Cylinder object.
Definition: JCylinder3D.hh:39
Data structure for vector in three dimensions.
Definition: JVector3D.hh:34
Mathematical constants.
double getX() const
Get x position.
Definition: JVector2D.hh:63
static const double PI
Mathematical constants.
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
JVector3D getRandomPosition(const JSphere3D &sphere)
Get random position.
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
Data structure for unit quaternion in three dimensions.
double getZmax() const
Get maximal z position.
Definition: JCylinder3D.hh:122
double getRadius() const
Get radius.
Definition: JSphere3D.hh:59
T getRandom()
Get random value.
Definition: JRandom.hh:113
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:26
void randomize(Vec *p)
Randomize 3D vector.