forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create 1401.Circle-and-Rectangle-Overlapping.cpp
- Loading branch information
1 parent
a6617b3
commit 3f9c6e2
Showing
1 changed file
with
14 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
Math/1401.Circle-and-Rectangle-Overlapping/1401.Circle-and-Rectangle-Overlapping.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Solution { | ||
public: | ||
bool checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2) | ||
{ | ||
double cx = (x2+x1)*1.0/2, cy = (y2+y1)*1.0/2; | ||
double hx = (x2-x1)*1.0/2, hy = (y2-y1)*1.0/2; | ||
double px = x_center, py = y_center; | ||
|
||
double vx = abs(px-cx), vy = abs(py-cy); | ||
double ux = max(vx-hx, 0.0), uy = max(vy-hy,0.0); | ||
|
||
return ux*ux+uy*uy <= radius*radius; | ||
} | ||
}; |