0

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.

I wrote my code in python with PySide6.

enter image description here

How should I do that?

How should I detect collision between POV and other objects?

DSA5252
  • 35
  • 6

1 Answers1

0

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.

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. 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.