Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JGeometry3DTestkit.hh
Go to the documentation of this file.
1#ifndef __JGEOMETRY3DTESTKIT__
2#define __JGEOMETRY3DTESTKIT__
3
4#include "TRandom3.h"
5
13#include "JMath/JRandom.hh"
14#include "JMath/JConstants.hh"
15
16/**
17 * \author mdejong
18 */
19
20namespace JGEOMETRY3D {}
21namespace JPP { using namespace JGEOMETRY3D; }
22
23namespace 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 */
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 */
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
Mathematical constants.
Definition of random value generator.
double getRadius() const
Get radius.
Definition JCircle2D.hh:144
double getY() const
Get y position.
Definition JVector2D.hh:74
double getX() const
Get x position.
Definition JVector2D.hh:63
double getZmin() const
Get minimal z position.
double getZmax() const
Get maximal z position.
Data structure for direction in three dimensions.
Data structure for Euler angles in three dimensions.
Data structure for position in three dimensions.
const JPosition3D & getPosition() const
Get position.
Data structure for unit quaternion in three dimensions.
double getRadius() const
Get radius.
Definition JSphere3D.hh:59
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
Data structure for normalised vector in three dimensions.
Definition JVersor3D.hh:28
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition JAngle3D.hh:19
void randomize(JPosition3D *p)
Randomize position.
JVector3D getRandomPosition(const JSphere3D &sphere)
Get random position.
T getRandom()
Get random value.
static const double PI
Mathematical constants.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).