-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathECCircle.cpp
More file actions
99 lines (67 loc) · 2.47 KB
/
ECCircle.cpp
File metadata and controls
99 lines (67 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "ECCircle.h"
#include <cmath>
using namespace std;
//*************************************************************************************
// Circle
ECCircle::ECCircle(double x, double y, double radius) : _xCenter(x), _yCenter(y), _radius(radius) {}
void ECCircle::GetBoundingBox(double &xUpperLeft, double &yUpperLeft, double &xLowerRight, double &yLowerRight) const {
double xMax = _xCenter + _radius;
double xMin = _xCenter - _radius;
double yMax = _yCenter + _radius;
double yMin = _yCenter - _radius;
xUpperLeft = xMin;
xLowerRight = xMax;
yUpperLeft = yMin;
yLowerRight = yMax;
}
// is the shape intersecting with point (px, py)
bool ECCircle::IsPointInside(const EC2DPoint &pt) const {
// sqrt( (x_p - x_c)^2 + (y_p - y_c)^2 ) <= radius if point is inside
double xp = pt.xCoord;
double yp = pt.yCoord;
double xc = _xCenter;
double yc = _yCenter;
double term1 = pow((xp - xc),2);
double term2 = pow((yp - yc),2);
double result = sqrt(term1 + term2);
return result <= _radius;
}
double ECCircle::GetArea() const {
return PI * _radius * _radius;
}
void ECCircle::GetCenter(double &xc, double &yc) const {
xc = _xCenter;
yc = _yCenter;
}
//*************************************************************************************
// Ellipse
ECEllipse::ECEllipse(double x, double y, double radiusx, double radiusy) : _xCenter(x), _yCenter(y), _radiusX(radiusx), _radiusY(radiusy) {}
void ECEllipse::GetBoundingBox(double &xUpperLeft, double &yUpperLeft, double &xLowerRight, double &yLowerRight) const {
double xMax = _xCenter + _radiusX;
double xMin = _xCenter - _radiusX;
double yMax = _yCenter + _radiusY;
double yMin = _yCenter - _radiusY;
xUpperLeft = xMin;
xLowerRight = xMax;
yUpperLeft = yMin;
yLowerRight = yMax;
}
// is the shape intersecting with point (px, py)
bool ECEllipse::IsPointInside(const EC2DPoint &pt) const {
// [ (x-h)^2 / r_x^2 ] + [ (y-k)^2 / r_y^2 ] <= 1 if inside ellipse
double h = _xCenter;
double k = _yCenter;
double x = pt.xCoord;
double y = pt.yCoord;
double term1 = ( pow((x-h), 2) ) / ( pow(_radiusX, 2) );
double term2 = ( pow((y-k), 2) ) / ( pow(_radiusY, 2) );
double result = term1 + term2;
return result <= 1;
}
double ECEllipse::GetArea() const {
return PI * _radiusX * _radiusY;
}
void ECEllipse::GetCenter(double &xc, double &yc) const {
xc = _xCenter;
yc = _yCenter;
}