57 const size_t Nmax = 1000,
58 const double precision = 1.0e-3)
63 const int N =
distance(__begin, __end);
77 for (T p = __begin; p != __end; ++p) {
81 A.a00 += p->getX() * U[i] * p->getX();
82 A.a01 += p->getX() * U[i] * p->getY();
83 A.a02 += p->getX() * U[i] * 1.0;
85 A.a11 += p->getY() * U[i] * p->getY();
86 A.a12 += p->getY() * U[i] * 1.0;
88 A.a22 += 1.0 * U[i] * 1.0;
102 catch(exception& error) {
111 for (T p = __begin; p != __end; ++p) {
113 const double D = (p->getX() * (A.a00 * p->getX() + A.a01 * p->getY() + A.a02 * 1.0) +
114 p->getY() * (A.a10 * p->getX() + A.a11 * p->getY() + A.a12 * 1.0) +
115 1.0 * (A.a20 * p->getX() + A.a21 * p->getY() + A.a22 * 1.0));
123 double step = (Dmax - 3.0) / (3.0 * (Dmax - 1.0));
127 for (
int i = 0; i < N; ++i) {
128 U[i] = (1.0 - step) * U[i];
135 if (Dmax - 3.0 <= precision) {
144 for (T p = __begin; p != __end; ++p) {
155 for (T p = __begin; p != __end; ++p) {
159 const double x = p->getX() - this->
getX();
160 const double y = p->getY() - this->
getY();
162 B.
a00 += x * U[i] * x;
163 B.a01 += x * U[i] * y;
164 B.a11 += y * U[i] * y;
172 catch(exception& error) {
178 const double trace = B.a00 + B.a11;
179 const double D = sqrt((B.a00 - B.a11) * (B.a00 - B.a11) + 4.0 * B.a01 * B.a01);
181 const double lambda_1 = (trace - D) / 2.0;
182 const double lambda_2 = (trace + D) / 2.0;
184 this->
major = 1.0 / sqrt(lambda_1);
185 this->
minor = 1.0 / sqrt(lambda_2);
186 this->
angle = 0.5 * atan2(-2.0 * B.a01, B.a11 - B.a00);
194 for (T p = __begin; p != __end; ++p) {
202 const double F = hypot(pos.
getX() / this->major,
203 pos.
getY() / this->minor);
291 out << static_cast<const JPosition2D&>(ellipse);
349 const double st = sin(ellipse.
getAngle());
350 const double ct = cos(ellipse.
getAngle());
352 const double x = ellipse.
getX();
353 const double y = ellipse.
getY();
358 A = a*a * st*st + b*b * ct*ct;
359 B = 2.0 * (b*b - a*a) * st*ct;
360 C = a*a * ct*ct + b*b * st*st;
363 F = A*x*x + B*x*y + C*y*y - a*a * b*b;
391 return (*
this)(p) <= precision;
404 const double U = 4*A*C - B*
B;
406 return PI * 2.0 * (A*
E*
E + C*
D*
D - B*
D*
E - U*
F) / (U * sqrt(U));
419 return in >> ellipse.
A >> ellipse.
B >> ellipse.
C >> ellipse.
D >> ellipse.
E >> ellipse.
F;
434 return out << format << ellipse.
A <<
' '
435 << format << ellipse.
B <<
' '
436 << format << ellipse.
C <<
' '
437 << format << ellipse.
D <<
' '
438 << format << ellipse.
E <<
' '
439 << format << ellipse.
F;
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
JFormat_t & getFormat()
Get format for given type.
Data structure for position in two dimensions.
const JPosition2D & getPosition() const
Get position.
JPosition2D & rotate_back(const JRotation2D &R)
Rotate back.
JPosition2D()
Default constructor.
void setPosition(const JVector2D &pos)
Set position.
Data structure for vector in two dimensions.
double getY() const
Get y position.
double getX() const
Get x position.
JVector2D & add(const JVector2D &vector)
Add vector.
Exception for accessing a value in a collection that is outside of its range.
Auxiliary classes and methods for 2D geometrical objects and operations.
static const double PI
Mathematical constants.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
friend std::ostream & operator<<(std::ostream &out, const JEllipse2D_t &ellipse)
Write ellipse to output.
JEllipse2D_t(const double A, const double B, const double C, const double D, const double E, const double F)
Constructor.
double operator()(const JVector2D &p) const
Evaluate ellipse equation for given point.
bool is_inside(const JVector2D &p, const double precision=1.0e-8) const
Check if a point is inside or on the boundary of the ellipse.
friend std::istream & operator>>(std::istream &in, JEllipse2D_t &ellipse)
Read ellipse from input.
JEllipse2D_t(const JEllipse2D &ellipse)
Constructor.
double getArea() const
Get area.
static const int MINIMUM_NUMBER_OF_POINTS
double getMajorAxis() const
Get major axis.
JEllipse2D(T __begin, T __end, const size_t Nmax=1000, const double precision=1.0e-3)
Constructor.
double angle
rotation angle in radians
friend std::ostream & operator<<(std::ostream &out, const JEllipse2D &ellipse)
Write ellipse to output.
JEllipse2D()
Default constructor.
double getMinorAxis() const
Get minor axis.
friend std::istream & operator>>(std::istream &in, JEllipse2D &ellipse)
Read ellipse from input.
double getAngle() const
Get rotation angle.
size_t numberOfIterations
double getArea() const
Get area.