leetcode-5361-圆和矩形是否有重叠

Posted 真不知道叫啥好

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode-5361-圆和矩形是否有重叠相关的知识,希望对你有一定的参考价值。

题目描述:

 

 

class Solution:
    def checkOverlap(self, radius: int, x_center: int, y_center: int, x1: int, y1: int, x2: int, y2: int) -> bool:
        a = max(0, x1 - x_center, x_center - x2) ** 2 
        b = max(0, y1 - y_center, y_center - y2) ** 2
        c = radius ** 2
        return a + b <= c

class Solution:
    def checkOverlap(self, radius: int, x_center: int, y_center: int, x1: int, y1: int, x2: int, y2: int) -> bool:
        for x in (x1, x2):
            for y in (y1, y2):
                if dist((x_center, y_center), (x, y)) <= radius:
                    return True
        if x1 <= x_center <= x2 and y1 - radius  <= y_center <= y2 + radius:
            return True
        if x1 - radius <= x_center <= x2 + radius and y1  <= y_center <= y2:
            return True
        return False

 

以上是关于leetcode-5361-圆和矩形是否有重叠的主要内容,如果未能解决你的问题,请参考以下文章

怎样判断平面上一个矩形和一个圆形是否有重叠

swift - 画图 - 画矩形,虚线,圆和半圆

如何在圆和矩形上获得确切数量的笔划破折号?

Java检查两个矩形是不是在任何点重叠

给定两个矩形的坐标,找出矩形是不是重叠

opencv学习笔记基本图像的绘制——直线椭圆矩形圆和多边形