python - 检查点是否在旋转的矩形内
问题描述
我正在尝试检查一个点是否在旋转的矩形内。我发现: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
如何检查一个点是否与旋转的矩形发生碰撞?
解决方案
推荐阅读
- xml - 此代码应显示错误,因为存在比 dtd 额外的标记。但它没有显示任何错误。有什么问题?
- android - 监听 Firestore Websocket
- c++ - 避免来自 Regex_search 的额外匹配
- asp.net-core-mvc - 如何在 asp.net mvc-core 中读取和显示相关数据?
- azure - Azure Functions 使用 ASP.NET 的哪些部分?
- typescript - typescript 泛型限制数量 | 细绳
- java - 追踪 Vget 下载进度
- mongodb - Spring Boot MongoDB 通过 Ssh 隧道连接
- javascript - 随时从服务器填充 angularjs ui-select 将其放下
- iphone - 如何在 iPad 上使用 Java Script 播放音频?