Belle II Software development
Circle2D.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9#include <tracking/trackFindingCDC/geometry/Vector2D.h>
10
11#include <tracking/trackFindingCDC/numerics/ERightLeft.h>
12#include <tracking/trackFindingCDC/numerics/ERotation.h>
13#include <tracking/trackFindingCDC/numerics/ESign.h>
14
15#include <cmath>
16
17namespace Belle2 {
22 namespace TrackFindingCDC {
23
26 class Circle2D {
27
28 public:
31 : m_center(0.0, 0.0)
32 , m_radius(0.0)
33 {
34 }
35
37 Circle2D(const Vector2D& center, const double radius)
40 {
41 }
42
44 Circle2D(const Vector2D& center, const double absRadius, const ERotation ccwInfo)
46 , m_radius(fabs(absRadius) * static_cast<double>(ccwInfo))
47 {
48 }
49
50 public:
52 void reverse()
53 {
54 m_radius *= -1;
55 }
56
59 {
60 return Circle2D(center(), -radius());
61 }
62
75 {
76 double denominator = 1 / (center().normSquared() - radius() * radius());
77 m_center *= denominator;
78 m_radius *= -denominator;
79 }
80
93 {
94 double denominator = 1 / (center().normSquared() - radius() * radius());
95 return Circle2D(center() * denominator, -radius() * denominator);
96 }
97
98 public:
100 double distance(const Vector2D& point) const
101 {
102 return copysign(center().distance(point), radius()) - radius();
103 }
104
106 double impact() const
107 {
108 return copysign(center().norm(), radius()) - radius();
109 }
110
112 double absDistance(const Vector2D& point) const
113 {
114 return fabs(center().distance(point) - absRadius());
115 }
116
119 {
120 return static_cast<ERightLeft>(sign(distance(point)));
121 }
122
124 bool isLeft(const Vector2D& rhs) const
125 {
126 return isRightOrLeft(rhs) == ERightLeft::c_Left;
127 }
128
130 bool isRight(const Vector2D& rhs) const
131 {
132 return isRightOrLeft(rhs) == ERightLeft::c_Right;
133 }
134
136 Vector2D closest(const Vector2D& point) const
137 {
138 Vector2D connection = point - center();
139 connection.normalizeTo(absRadius());
140 connection += center();
141 return connection;
142 }
143
146 {
147 Vector2D connection = center();
148 connection.normalizeTo(-absRadius());
149 connection += center();
150 return connection;
151 }
152
155 {
156 return tangential(Vector2D(0.0, 0.0)).unit();
157 }
158
160 double tangentialPhi() const
161 {
162 return tangential().phi();
163 }
164
166 Vector2D gradient(const Vector2D& point) const
167 {
168 Vector2D connection = (point - center()) * orientation();
169 return connection.unit();
170 }
171
173 Vector2D normal(const Vector2D& point) const
174 {
175 return gradient(point).unit();
176 }
177
179 Vector2D tangential(const Vector2D& point) const
180 {
181 return normal(point).orthogonal();
182 }
183
185 double openingAngle(const Vector2D& from, const Vector2D& to) const
186 {
187 return gradient(from).angleWith(gradient(to));
188 } // can be optimized in the number of computations
189
191 double arcLengthBetween(const Vector2D& from, const Vector2D& to) const
192 {
193 return openingAngle(from, to) * radius();
194 }
195
197 double radius() const
198 {
199 return m_radius;
200 }
201
203 double radiusSquared() const
204 {
205 return radius() * radius();
206 }
207
209 double absRadius() const
210 {
211 return fabs(radius());
212 }
213
216 {
217 return static_cast<ERotation>(sign(radius()));
218 }
219
222 {
223 return m_center;
224 }
225
229 void moveBy(const Vector2D& by)
230 {
231 m_center += by;
232 }
233
235 void moveAlongFirst(const double first)
236 {
237 m_center.setFirst(m_center.first() + first);
238 }
239
241 void moveAlongSecond(const double second)
242 {
243 m_center.setSecond(m_center.second() + second);
244 }
245
247 void passiveMoveBy(const Vector2D& by)
248 {
249 m_center -= by;
250 }
251
253 void passiveMoveAlongFirst(const double first)
254 {
255 m_center.setFirst(m_center.first() - first);
256 }
257
259 void passiveMoveAlongSecond(const double second)
260 {
261 m_center.setSecond(m_center.second() - second);
262 }
265 private:
268
270 double m_radius;
271
272 };
273 }
275}
A two dimensional circle in its natural representation using center and radius as parameters.
Definition: Circle2D.h:26
Circle2D reversed() const
Returns a copy of the line with the reversed orientation.
Definition: Circle2D.h:58
Vector2D tangential() const
Gives the tangential vector at the closest approach to the origin / at the perigee.
Definition: Circle2D.h:154
double absDistance(const Vector2D &point) const
Returns the euclidian distance of the point to the circle line.
Definition: Circle2D.h:112
double m_radius
Memory for the signed radius.
Definition: Circle2D.h:270
double openingAngle(const Vector2D &from, const Vector2D &to) const
Calculates the angle between two points as seen from the center of the circle.
Definition: Circle2D.h:185
Vector2D perigee() const
Returns the point closest to the origin.
Definition: Circle2D.h:145
Vector2D gradient(const Vector2D &point) const
Gradient of the distance field.
Definition: Circle2D.h:166
Vector2D tangential(const Vector2D &point) const
Tangential vector to the circle near the given position.
Definition: Circle2D.h:179
double arcLengthBetween(const Vector2D &from, const Vector2D &to) const
Calculates the arc length between two points of closest approach on the circle.
Definition: Circle2D.h:191
void reverse()
Flips orientation the circle in place.
Definition: Circle2D.h:52
double radius() const
Getter for the signed radius.
Definition: Circle2D.h:197
Vector2D normal(const Vector2D &point) const
Normal vector to the circle near the given position.
Definition: Circle2D.h:173
Vector2D m_center
Memory for the central point.
Definition: Circle2D.h:267
double distance(const Vector2D &point) const
Calculates the signed distance of the point to the circle line.
Definition: Circle2D.h:100
void passiveMoveBy(const Vector2D &by)
Passivelly move the coordinate system in place by the given vector.
Definition: Circle2D.h:247
bool isLeft(const Vector2D &rhs) const
Return if the point given is left of the circle line.
Definition: Circle2D.h:124
bool isRight(const Vector2D &rhs) const
Return if the point given is right of the circle line.
Definition: Circle2D.h:130
Circle2D conformalTransformed() const
Returns a copy of the circle in conformal space.
Definition: Circle2D.h:92
void moveAlongFirst(const double first)
Activelly moves the circle in the direction given in place along the first coordinate.
Definition: Circle2D.h:235
double impact() const
Returns the signed distance to the origin.
Definition: Circle2D.h:106
Vector2D center() const
Getter for the central point of the circle.
Definition: Circle2D.h:221
Circle2D()
Default constructor for ROOT compatibility. Creates an invalid circle.
Definition: Circle2D.h:30
void passiveMoveAlongFirst(const double first)
Passivelly move the coordinate system in place along the first coordinate.
Definition: Circle2D.h:253
double radiusSquared() const
Getter for the squared radius.
Definition: Circle2D.h:203
void conformalTransform()
Transforms the circle to conformal space inplace.
Definition: Circle2D.h:74
void moveBy(const Vector2D &by)
Activelly moves the circle in the direction given in place by the vector given.
Definition: Circle2D.h:229
ERightLeft isRightOrLeft(const Vector2D &point) const
Return if the point given is right or left of the line.
Definition: Circle2D.h:118
double absRadius() const
Getter for the absolute radius.
Definition: Circle2D.h:209
Vector2D closest(const Vector2D &point) const
Calculates the point of closest approach on the line to the point.
Definition: Circle2D.h:136
double tangentialPhi() const
Gives to azimuth phi of the direction of flight at the perigee.
Definition: Circle2D.h:160
void passiveMoveAlongSecond(const double second)
Passivelly move the coordinate system in place along the second coordinate.
Definition: Circle2D.h:259
Circle2D(const Vector2D &center, const double radius)
Constructs a circle with given center and radius/ orientation as given by the signedRadius.
Definition: Circle2D.h:37
ERotation orientation() const
Indicates if the circle is to be interpreted counterclockwise or clockwise.
Definition: Circle2D.h:215
Circle2D(const Vector2D &center, const double absRadius, const ERotation ccwInfo)
Constructs a circle with given center, absolut value of the radius and orientation.
Definition: Circle2D.h:44
void moveAlongSecond(const double second)
Activelly moves the circle in the direction given in place along the second coordinate.
Definition: Circle2D.h:241
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:32
void setSecond(const double second)
Setter for the second coordinate.
Definition: Vector2D.h:644
double normalizeTo(const double toLength)
Normalizes the vector to the given length.
Definition: Vector2D.h:313
double phi() const
Gives the azimuth angle being the angle to the x axes ( range -M_PI to M_PI )
Definition: Vector2D.h:569
double second() const
Getter for the second coordinate.
Definition: Vector2D.h:639
double normSquared() const
Calculates .
Definition: Vector2D.h:169
Vector2D orthogonal() const
Orthogonal vector to the counterclockwise direction.
Definition: Vector2D.h:289
double first() const
Getter for the first coordinate.
Definition: Vector2D.h:629
Vector2D unit() const
Returns a unit vector colaligned with this.
Definition: Vector2D.h:321
double angleWith(const Vector2D &rhs) const
The angle between this and rhs.
Definition: Vector2D.h:197
void setFirst(const double first)
Setter for the first coordinate.
Definition: Vector2D.h:634
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition: ERightLeft.h:25
ERotation
Enumeration to represent the distinct possibilities of the right left passage information.
Definition: ERotation.h:25
Abstract base class for different kinds of events.