圆和矩形是否重叠 x1<x2, y1<y2 https://www.zhihu.com/question/24251545/answer/27184960 LC1401/双周赛23C https://leetcode-cn.com/contest/biweekly-contest-23/problems/circle-and-rectangle-overlapping/
(r, ox, oy, x1, y1, x2, y2 int)
| 679 | // https://www.zhihu.com/question/24251545/answer/27184960 |
| 680 | // LC1401/双周赛23C https://leetcode-cn.com/contest/biweekly-contest-23/problems/circle-and-rectangle-overlapping/ |
| 681 | func isCircleRectangleOverlap(r, ox, oy, x1, y1, x2, y2 int) bool { |
| 682 | cx, cy := float64(x1+x2)/2, float64(y1+y2)/2 // 矩形中心 |
| 683 | hx, hy := float64(x2-x1)/2, float64(y2-y1)/2 // 矩形半长 |
| 684 | x, y := math.Abs(float64(ox)-cx), math.Abs(float64(oy)-cy) // 转换到第一象限的圆心 |
| 685 | x, y = math.Max(x-hx, 0), math.Max(y-hy, 0) // 求圆心至矩形的最短距离矢量 |
| 686 | return x*x+y*y < float64(r*r)+eps |
| 687 | } |
| 688 | |
| 689 | // 圆与扫描线 |
| 690 | // todo https://blog.csdn.net/hzj1054689699/article/details/87861808 |
nothing calls this directly
no outgoing calls
no test coverage detected