检查点是否在旋转矩形内

时间:2021-03-08 11:01:25

标签: python rotation collision-detection

我正在尝试检查一个点是否在旋转的矩形内。 我发现: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

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

0 个答案:

没有答案
相关问题