Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JGeometry3D.cc File Reference

Example program to test rotations in 3D. More...

#include <iostream>
#include <iomanip>
#include "TRandom3.h"
#include "JTools/JQuantile.hh"
#include "JGeometry3D/JPosition3D.hh"
#include "JGeometry3D/JAngle3D.hh"
#include "JGeometry3D/JRotation3D.hh"
#include "JGeometry3D/JQuaternion3D.hh"
#include "JMath/JMathToolkit.hh"
#include "JMath/JConstants.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test rotations in 3D.

Author
mdejong

Definition in file JGeometry3D.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 26 of file JGeometry3D.cc.

27{
28 using namespace std;
29
30 int numberOfEvents;
31 double precision;
32 ULong_t seed;
33 int debug;
34
35 try {
36
37 JParser<> zap("Example program to test rotations in 3D.");
38
39 zap['n'] = make_field(numberOfEvents);
40 zap['e'] = make_field(precision) = 1.0e-12;
41 zap['S'] = make_field(seed) = 0;
42 zap['d'] = make_field(debug) = 1;
43
44 zap(argc, argv);
45 }
46 catch(const exception &error) {
47 FATAL(error.what() << endl);
48 }
49
50 gRandom->SetSeed(seed);
51
52 using namespace JPP;
53
54
55 JQuantile Q("Distance");
56
57 const JVector3D v[] = { JVector3D(1,0,0), // unit vector along x-axis
58 JVector3D(0,1,0), // unit vector along y-axis
59 JVector3D(0,0,1) }; // unit vector along z-axis
60
61 for (int i = 0; i != numberOfEvents; ++i) {
62
63 STATUS("event: " << setw(10) << i << '\r'); DEBUG(endl);
64
65 const double theta = gRandom->Uniform(0.0, PI);
66 const double phi = gRandom->Uniform(0.0, 2*PI);
67
68 const JAngle3D dir(theta, phi); // principal direction
69 const JRotation3D R(dir);
70
71 //const JRotation3Y Ry(theta); // rotation around y-axis
72 //const JRotation3Z Rz(phi); // rotation around z-axis
73
74 //const JQuaternion3D Ry(theta, JVersor3D(0,1,0)); // rotation around y-axis
75 //const JQuaternion3D Rz(phi, JVersor3D(0,0,1)); // rotation around z-axis
76
77 const JQuaternion3X Rx(0.0); // rotation around x-axis
78 const JQuaternion3Y Ry(theta); // rotation around y-axis
79 const JQuaternion3Z Rz(phi); // rotation around z-axis
80
81 //const JQuaternion3D Rs = Rz * Ry;
82 JQuaternion3D Rs(Rx, Ry, Rz);
83 /*
84 Rs.setIdentity();
85 Rs *= Rz;
86 Rs *= Ry;
87 */
88 for (int j = 0; j != sizeof(v)/sizeof(v[0]); ++j) {
89
90 JPosition3D A(v[j]);
91 JPosition3D B(A);
92
93 //B.rotate(Ry); // rotates around y-axis
94 //B.rotate(Rz); // rotates around z-axis
95 B.rotate(Rs);
96
97 B.rotate(R); // rotates principal direction to z-axis
98
99
100 Q.put((B - A).getLength());
101
102 if ((B - A).getLengthSquared() > precision*precision) {
103
104 DEBUG("theta " << theta << endl);
105 DEBUG("phi " << phi << endl);
106
107 //DEBUG("Ry" << endl << Ry);
108 //DEBUG("Rz" << endl << Rz);
109
110 DEBUG("R " << endl << R);
111
112 ERROR("A " << FIXED(7,3) << A.getX() << ' ' << A.getY() << ' ' << A.getZ() << endl);
113 ERROR("B " << FIXED(7,3) << B.getX() << ' ' << B.getY() << ' ' << B.getZ() << endl);
114 }
115 }
116 }
117 STATUS(endl);
118
119 Q.print(cout);
120}
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define ERROR(A)
Definition JMessage.hh:66
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Data structure for angles in three dimensions.
Definition JAngle3D.hh:35
Data structure for position in three dimensions.
Data structure for unit quaternion in three dimensions.
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
int j
Definition JPolint.hh:801
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
This class represents a rotation around the x-axis.
This class represents a rotation around the y-axis.
This class represents a rotation around the z-axis.
Auxiliary data structure for running average, standard deviation and quantiles.
Definition JQuantile.hh:46