简体   繁体   English

object的POV与圆形、矩形的碰撞检测

[英]Collision detection between POV of object and circles and rectangles

in " Drawing point of view for an object in PyQt6 " we made a point of view for an object. and in " Collision detection between circle and rectangle " we found methods how to detect collision between circles and rectangles now I want to detect collision between POV and other objects like this.在“ Drawing point of view for an object in PyQt6 ”中,我们为 object 绘制了一个视角。在“ Collision detection between circle and rectangle ”中,我们找到了如何检测圆形和矩形之间碰撞的方法,现在我想检测两者之间的碰撞POV 和其他类似的对象。

I wrote my code in python with PySide6.我用 PySide6 在 python 中编写了我的代码。

在此处输入图像描述

How should I do that?我该怎么做?

How should I detect collision between POV and other objects?我应该如何检测 POV 与其他物体之间的碰撞?

If you have the option of working directly with a bitmap, you can paint the obstacles, then paint the POV and check if every pixel is free.如果您可以选择直接使用 bitmap,您可以绘制障碍物,然后绘制 POV 并检查每个像素是否空闲。

Otherwise, you can decompose the POV as the union of a disk and a sector, and detect the collisions with the disk or the sector.否则,您可以将 POV 分解为磁盘和扇区的并集,并检测与磁盘扇区的冲突。 Detecting collisions between two circles is not a big deal (compare the distance between the centers to the sum of the radii), and you linked to the collision between a disk and a rectangle.检测两个圆之间的碰撞不是什么大问题(比较中心之间的距离与半径之和),并且您将其与圆盘和矩形之间的碰撞联系起来。 Detecting collisions with a sector is more challenging.检测与扇区的碰撞更具挑战性。

You can decompose this operation as a collision with a disk and with an angle, itself defined as the intersection of two half-planes.您可以将此操作分解为与圆盘角度的碰撞,该角度本身定义为两个半平面的交点。 Intersection with a half-plane is not difficult.与半平面相交并不困难。 For a disk, compare the algebraic distance of the center to the border line and the disk radius.对于圆盘,比较中心到边界线的代数距离和圆盘半径。 For a rectangle, check that at least one of the corners lies in the half plane.对于矩形,检查至少有一个角位于半平面内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM