-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path478.cpp
More file actions
32 lines (28 loc) · 999 Bytes
/
478.cpp
File metadata and controls
32 lines (28 loc) · 999 Bytes
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
class Solution {
public:
double square;
double x_center;
double y_center;
Solution(double radius, double x_center, double y_center) {
square = radius * radius;
this->x_center = x_center;
this->y_center = y_center;
}
double randomDouble(double minVal, double maxVal) {
return (maxVal - minVal) * ((double)rand() / (double)RAND_MAX) + minVal;
}
vector<double> randPoint() {
double randSquare = randomDouble(0, square);
double randLength = sqrt(randSquare);
double randomDegree = randomDouble(0, 360);
double randomRad = randomDegree * 3.14159 / 180.0;
double x = cos(randomRad) * randLength + x_center;
double y = sin(randomRad) * randLength + y_center;
return {x, y};
}
};
/**
* Your Solution object will be instantiated and called as such:
* Solution* obj = new Solution(radius, x_center, y_center);
* vector<double> param_1 = obj->randPoint();
*/