首页 > 解决方案 > 检查点是否在旋转的矩形内

问题描述

我正在尝试检查一个点是否在旋转的矩形内。我发现:https ://gamedev.stackexchange.com/questions/128598/collision-detection-point-hitting-a-rotating-rectangle

但它不起作用......这是我的python代码:

    def collides(point_x, point_y, x_rect, y_rect, width_rect, height_rect, center_rect_x, center_rect_y, angle_rect):
        radians = angle_rect / 180.0 * math.pi
        angle_sin = math.sin(radians)
        angle_cos = math.cos(radians)

        x = ((point_x - center_rect_x) * angle_cos - (point_y - center_rect_y) * angle_sin) + center _rect_x
        y = ((point_x - center_rect_x) * angle_sin + (point_y - center_rect_y) * angle_cos) + center_rect_y

        return x > x_rect and x < x_rect + width_rect and y > y_rect and y < y_rect + height_rect

如何检查一个点是否与旋转的矩形发生碰撞?

标签: pythonrotationcollision-detection

解决方案


推荐阅读