testGeometryUtilities.cc
Go to the documentation of this file.
1 #include <cmath>
2 #include <utl/CoordinateSystem.h>
3 #include <utl/GeometryUtilities.h>
4 #include <utl/Math.h>
5 #include <utl/MathConstants.h>
6 #include <utl/Test.h>
7 
8 #include <cppunit/extensions/HelperMacros.h>
9 
10 #include <iostream>
11 
12 using namespace std;
13 using namespace utl;
14 
15 
16 #define TEST(x...) CPPUNIT_ASSERT(Test x)
17 
18 
27 class testGeometryUtilities : public CppUnit::TestFixture {
28 
29  CPPUNIT_TEST_SUITE(testGeometryUtilities);
30  CPPUNIT_TEST(testNormalizeAngleMinusPiPi);
31  CPPUNIT_TEST(testPlaneCtor);
32  CPPUNIT_TEST(testLineCtor);
33  CPPUNIT_TEST(testLineLineDistance);
34  CPPUNIT_TEST(testLinePointDistance);
35  CPPUNIT_TEST(testPlanePointDistance);
36  CPPUNIT_TEST(testPlanePlaneIntersection1);
37  CPPUNIT_TEST(testPlanePlaneIntersection2);
38  CPPUNIT_TEST(testPlanePlaneIntersection3);
39  CPPUNIT_TEST(testLinePlaneIntersection1);
40  CPPUNIT_TEST(testPerpendicularProjection);
41  CPPUNIT_TEST_SUITE_END();
42 
43 private:
44  void
45  CheckIntersection(const Plane& plane1, const Plane& plane2,
46  const Vector& resDirection, const Point& resAnchor)
47  const
48  {
49  const Line line = Intersection(plane1, plane2);
50  const Vector& dir = line.GetDirection();
51  const Point& anch = line.GetAnchor();
52  TEST(<CloseTo>(Distance(plane1, anch), 0.));
53  TEST(<CloseTo>(Distance(plane2, anch), 0.));
54  TEST(<CloseTo>(Distance(line, anch), 0.));
55  TEST(<CloseTo>(dir.GetCoordinates(fCS), resDirection.GetCoordinates(fCS)));
56  TEST(<CloseTo>(anch.GetCoordinates(fCS), resAnchor.GetCoordinates(fCS)));
57  }
58 
59  void
60  CheckIntersection(const Plane& plane, const Line& line,
61  const Point& resPoint)
62  const
63  {
64  const Point point = Intersection(plane, line);
65  TEST(<CloseTo>(Distance(plane, point), 0.));
66  TEST(<CloseTo>(Distance(line, point), 0.));
67  TEST(<CloseTo>(point.GetCoordinates(fCS), resPoint.GetCoordinates(fCS)));
68  }
69 
70  void
71  CheckProjection(const Plane& plane, const Point& point,
72  const Point& resPoint)
73  const
74  {
75  TEST(<CloseTo>(Distance(plane, resPoint), 0.));
76  const Point proj = PerpendicularProjection(plane, point);
77  TEST(<CloseTo>(Distance(plane, proj), 0.));
78  }
79 
81 
82 public:
83  void setUp() { fCS = CoordinateSystem::GetRootCoordinateSystem(); }
84 
85  void tearDown() { }
86 
87  void
89  {
91  TEST(<Equal>(NormalizeAngleMinusPiPi(-2.), -2.));
92  TEST(<CloseTo>(NormalizeAngleMinusPiPi(0.1 + kPi), 0.1 - kPi));
93  TEST(<CloseTo>(NormalizeAngleMinusPiPi(0.1 + 2*kPi), 0.1));
94  TEST(<CloseTo>(NormalizeAngleMinusPiPi(0.1 + 3*kPi), 0.1 - kPi));
95  TEST(<CloseTo>(NormalizeAngleMinusPiPi(-0.1 - kPi), -0.1 + kPi));
96  TEST(<CloseTo>(NormalizeAngleMinusPiPi(-0.1 - 2*kPi), -0.1));
97  TEST(<CloseTo>(NormalizeAngleMinusPiPi(-0.1 - 3*kPi), -0.1 + kPi));
98  }
99 
100  void
102  {
103  const Plane plane(Point(1,2,3, fCS), Vector(4,5,6, fCS));
104  TEST(<Equal>(plane.GetAnchor().GetCoordinates(fCS), Triple(1,2,3)));
105  TEST(<CloseTo>(plane.GetNormal().GetMag(), 1.));
106  }
107 
108  void
110  {
111  const Line line(Point(1,2,3, fCS), Vector(4,5,6, fCS));
112  TEST(<Equal>(line.GetAnchor().GetCoordinates(fCS), Triple(1,2,3)));
113  TEST(<CloseTo>(line.GetDirection().GetMag(), 1.));
114  }
115 
116  void
118  {
119  const Line line1(Point(1,0,0, fCS), Vector(1,0,0, fCS));
120  const Line line2(Point(0,1,0, fCS), Vector(0,0,1, fCS));
121  const Line line3(Point(0,1,1, fCS), Vector(0,0,1, fCS));
122  TEST(<CloseTo>(Distance(line1, line2), 1.));
123  TEST(<CloseTo>(Distance(line1, line3), 1.));
124  }
125 
126  void
128  {
129  const Line line(Point(0,0,0, fCS), Vector(1,0,0, fCS));
130  TEST(<CloseTo>(Distance(line, Point(3,0,1, fCS)), 1.));
131  TEST(<CloseTo>(Distance(line, Point(3,0,1, fCS)+line.GetDirection()), 1.));
132  TEST(<CloseTo>(Distance(line, Point(-1,0,0, fCS)), 0.));
133  TEST(<CloseTo>(Distance(line, Point(1,1,1, fCS)), sqrt(2.)));
134  }
135 
136  void
138  {
139  const Plane plane(Point(1,1,1, fCS), Vector(1,1,1, fCS));
140  TEST(<CloseTo>(Distance(plane, Point(0,0,0, fCS)), -sqrt(3.)));
141  TEST(<CloseTo>(Distance(plane, Point(2,2,2, fCS)), sqrt(3.)));
142  TEST(<CloseTo>(Distance(plane, Point(2,2,2, fCS)+Vector(-1,0,1, fCS)), sqrt(3.)));
143  }
144 
145  void
147  {
148  // x=0 and y=0 planes
149  CheckIntersection(Plane(Point(0,0,0, fCS), Vector(1,0,0, fCS)),
150  Plane(Point(0,0,0, fCS), Vector(0,1,0, fCS)),
151  Vector(0,0,1, fCS),
152  Point(0,0,0, fCS));
153  CheckIntersection(Plane(Point(1,0,0, fCS), Vector(1,0,0, fCS)),
154  Plane(Point(0,0,0, fCS), Vector(0,1,0, fCS)),
155  Vector(0,0,1, fCS),
156  Point(1,0,0, fCS));
157  CheckIntersection(Plane(Point(0,0,0, fCS), Vector(1,0,0, fCS)),
158  Plane(Point(0,1,0, fCS), Vector(0,1,0, fCS)),
159  Vector(0,0,1, fCS),
160  Point(0,1,0, fCS));
161  CheckIntersection(Plane(Point(1,0,0, fCS), Vector(1,0,0, fCS)),
162  Plane(Point(0,1,0, fCS), Vector(0,1,0, fCS)),
163  Vector(0,0,1, fCS),
164  Point(1,1,0, fCS));
165  }
166 
167  void
169  {
170  CheckIntersection(Plane(Point(0,2,2, fCS), Vector(1,0,0, fCS)),
171  Plane(Point(0,0,0, fCS), Vector(0,1,0, fCS)),
172  Vector(0,0,1, fCS),
173  Point(0,0,1, fCS));
174  }
175 
176  void
178  {
179  CheckIntersection(Plane(Point(1,1,1, fCS), Vector(0,0,1, fCS)),
180  Plane(Point(2,2,0, fCS), Vector(1,1,1, fCS)),
181  Vector(-sqrt(2.)/2,sqrt(2.)/2,0, fCS),
182  Point(1.5,1.5,1, fCS));
183  }
184 
185  void
187  {
188  CheckIntersection(Plane(Point(0,0,0, fCS), Vector(1,0,0, fCS)),
189  Line(Point(1,1,1, fCS), Vector(-1,-1,1, fCS)),
190  Point(0,0,2, fCS));
191  }
192 
193  void
195  {
196  CheckProjection(Plane(Point(2,2,0, fCS), Vector(0,0,1, fCS)),
197  Point(1,1,1, fCS), Point(1,1,0, fCS));
198  }
199 
200 };
201 
202 
double Plane(const utl::Point &point, const utl::Vector &normal, const utl::Photon &photonIn, utl::Photon &photonOut)
Definition: RTFunctions.cc:41
double NormalizeAngleMinusPiPi(const double x)
Normalize angle to lie between -pi and pi (-180 and 180 deg)
Point object.
Definition: Point.h:32
#define TEST(x...)
const Point & GetAnchor() const
Definition: Plane.h:22
double GetMag() const
Definition: Vector.h:58
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
Line Intersection(const Plane &p1, const Plane &p2)
Predicate for equality.
Definition: Test.h:33
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
boost::tuple< double, double, double > Triple
Coordinate triple for easy getting or setting of coordinates.
Definition: Triple.h:15
Class describing a Plane object.
Definition: Plane.h:17
constexpr double kPi
Definition: MathConstants.h:24
void CheckProjection(const Plane &plane, const Point &point, const Point &resPoint) const
double Distance(const Point &p, const sdet::Station &s)
void CheckIntersection(const Plane &plane1, const Plane &plane2, const Vector &resDirection, const Point &resAnchor) const
Vector object.
Definition: Vector.h:30
const Vector & GetDirection() const
Definition: Line.h:22
const Point & GetAnchor() const
Definition: Line.h:21
const Vector & GetNormal() const
Definition: Plane.h:23
Point PerpendicularProjection(const Point &point, const Plane &plane)
Definition: Line.h:17
void CheckIntersection(const Plane &plane, const Line &line, const Point &resPoint) const
Predicate for approximate equality (for floating point)
Definition: Test.h:91

, generated on Tue Sep 26 2023.