Problems with rounding numbers, halving, and offset when detecting collisions

24 Views Asked by At

I will try to visually explain my problem with an example.

There is some object (Fig. 1). The basis of the object is a straight line segment, which is defined by two points p0 and p1. A frame is created around this segment with an offset of 1 unit (like an OrientedBoundingBox). The frame is defined by four points. All coordinates are rounded to the nearest integer value.

Next we check if this object collides with the wall. We see that the wall does not fall inside the created frame, i.e. there is no collision.

At some point we need to split the red object in half. To do this, we divide the segment in half to get the midpoint. Round the coordinates of the midpoint. Then we create a frame with a thickness of 1 unit around the new segment (blue line in Fig. 2).

Next we check whether this new object collides with the wall. The wall now falls inside the frame of the newly created object (Fig. 3).

What is the best way to ensure that before dividing a segment and after dividing it, the result of checking for a collision with another object (wall) gives the same result.

As I understand, we need to double the thickness (add some EPSILON). I don't know if I'm right, and how to check/prove it? Then the second question arises - should we also increase the thickness for the new segment...

enter image description here

enter image description here

enter image description here

0

There are 0 best solutions below