ATLAS Offline Software
Loading...
Searching...
No Matches
EllipseCollisionTest Class Reference
Collaboration diagram for EllipseCollisionTest:

Public Member Functions

bool collide (double x0, double y0, double w, double h, double x1, double y1, double r) const
 EllipseCollisionTest (int maxIterations)

Private Member Functions

bool iterate (double x, double y, double c0x, double c0y, double c2x, double c2y, double rr) const

Private Attributes

int m_maxIterations

Detailed Description

Definition at line 20 of file AnnulusBounds.cxx.

Constructor & Destructor Documentation

◆ EllipseCollisionTest()

EllipseCollisionTest::EllipseCollisionTest ( int maxIterations)
inlineexplicit

Definition at line 118 of file AnnulusBounds.cxx.

119 : m_maxIterations(maxIterations)
120 {
121 }

Member Function Documentation

◆ collide()

bool EllipseCollisionTest::collide ( double x0,
double y0,
double w,
double h,
double x1,
double y1,
double r ) const
inline

Definition at line 92 of file AnnulusBounds.cxx.

93 {
94 double x = std::abs(x1 - x0);
95 double y = std::abs(y1 - y0);
96
97 // return iterate(x, y, w, 0, 0, h, r*r);
98
99 if (r > 0) {
100 if (x * x + (h - y) * (h - y) <= r * r || (w - x) * (w - x) + y * y <= r * r ||
101 x * h + y * w <= w * h // collision with (0, h)
102 || ((x * h + y * w - w * h) * (x * h + y * w - w * h) <= r * r * (w * w + h * h) && x * w - y * h >= -h * h &&
103 x * w - y * h <= w * w)) { // collision with (0, h)---(w, 0)
104 return true;
105 }
106 if ((x - w) * (x - w) + (y - h) * (y - h) <= r * r || (x <= w && y - r <= h) || (y <= h && x - r <= w)) {
107 return iterate(x, y, w, 0, 0, h, r * r); // collision within triangle (0, h) (w, h) (0, 0) is possible
108 }
109 return false;
110
111 }
112 double R = -r;
113 double localCos = x / R;
114 double deltaR = std::sqrt(h * h + (w * w - h * h) * localCos * localCos);
115 return deltaR >= R - std::sqrt(x * x + y * y);
116
117 }
Scalar deltaR(const MatrixBase< Derived > &vec) const
#define y
#define x
bool iterate(double x, double y, double c0x, double c0y, double c2x, double c2y, double rr) const
int r
Definition globals.cxx:22
double R(const INavigable4Momentum *p1, const double v_eta, const double v_phi)

◆ iterate()

bool EllipseCollisionTest::iterate ( double x,
double y,
double c0x,
double c0y,
double c2x,
double c2y,
double rr ) const
inlineprivate

Definition at line 24 of file AnnulusBounds.cxx.

25 {
26 std::vector<double> innerPolygonCoef(m_maxIterations + 1);
27 std::vector<double> outerPolygonCoef(m_maxIterations + 1);
28
29 for (int t = 1; t <= m_maxIterations; t++) {
30 int numNodes = 4 << t;
31 // innerPolygonCoef[t] = 0.5/std::cos(4*std::acos(0.0)/numNodes);
32 innerPolygonCoef[t] = 0.5 / std::cos(2.0*M_PI / numNodes);
33 double c1x = (c0x + c2x) * innerPolygonCoef[t];
34 double c1y = (c0y + c2y) * innerPolygonCoef[t];
35 double tx = x - c1x; // t indicates a translated coordinate
36 double ty = y - c1y;
37 if (tx * tx + ty * ty <= rr) {
38 return true; // collision with t1
39 }
40 double t2x = c2x - c1x;
41 double t2y = c2y - c1y;
42 if (tx * t2x + ty * t2y >= 0 && tx * t2x + ty * t2y <= t2x * t2x + t2y * t2y &&
43 (ty * t2x - tx * t2y >= 0 || rr * (t2x * t2x + t2y * t2y) >= (ty * t2x - tx * t2y) * (ty * t2x - tx * t2y))) {
44 return true; // collision with t1---t2
45 }
46 double t0x = c0x - c1x;
47 double t0y = c0y - c1y;
48 if (tx * t0x + ty * t0y >= 0 && tx * t0x + ty * t0y <= t0x * t0x + t0y * t0y &&
49 (ty * t0x - tx * t0y <= 0 || rr * (t0x * t0x + t0y * t0y) >= (ty * t0x - tx * t0y) * (ty * t0x - tx * t0y))) {
50 return true; // collision with t1---t0
51 }
52 outerPolygonCoef[t] = 0.5 / (std::cos(M_PI / numNodes) * std::cos(M_PI / numNodes));
53 double c3x = (c0x + c1x) * outerPolygonCoef[t];
54 double c3y = (c0y + c1y) * outerPolygonCoef[t];
55 if ((c3x - x) * (c3x - x) + (c3y - y) * (c3y - y) < rr) {
56 c2x = c1x;
57 c2y = c1y;
58 continue; // t3 is inside circle
59 }
60 double c4x = c1x - c3x + c1x;
61 double c4y = c1y - c3y + c1y;
62 if ((c4x - x) * (c4x - x) + (c4y - y) * (c4y - y) < rr) {
63 c0x = c1x;
64 c0y = c1y;
65 continue; // t4 is inside circle
66 }
67 double t3x = c3x - c1x;
68 double t3y = c3y - c1y;
69 if (ty * t3x - tx * t3y <= 0 || rr * (t3x * t3x + t3y * t3y) > (ty * t3x - tx * t3y) * (ty * t3x - tx * t3y)) {
70 if (tx * t3x + ty * t3y > 0) {
71 if (std::abs(tx * t3x + ty * t3y) <= t3x * t3x + t3y * t3y ||
72 (x - c3x) * (c0x - c3x) + (y - c3y) * (c0y - c3y) >= 0) {
73 c2x = c1x;
74 c2y = c1y;
75 continue; // circle center is inside t0---t1---t3
76 }
77 } else if (-(tx * t3x + ty * t3y) <= t3x * t3x + t3y * t3y ||
78 (x - c4x) * (c2x - c4x) + (y - c4y) * (c2y - c4y) >= 0) {
79 c0x = c1x;
80 c0y = c1y;
81 continue; // circle center is inside t1---t2---t4
82 }
83 }
84 return false; // no collision possible
85 }
86 return false; // out of iterations so it is unsure if there was a collision. But have to return something.
87 }
const boost::regex rr(r_r)
#define M_PI

Member Data Documentation

◆ m_maxIterations

int EllipseCollisionTest::m_maxIterations
private

Definition at line 23 of file AnnulusBounds.cxx.


The documentation for this class was generated from the following file: