简体   繁体   中英

How do you find the Point of Impact and Time of Impact between concave polygons and/or circles

I've got a collections of objects, each object is either a polygon or a circle, each with translation-vectors and rotation around a point.

I haven't really been able to try anything yet but from some research I know that you have to split the concave polygons into convex polygons and then apply a collision algorithm to them.

From my research, SAT came up a lot but some others did too, a lot of the related posts I found were quite old so the links and references weren't usable anymore.

The problem is that I don't know if they let you get the Point of Impact and Time of Impact or just let you translate the objects along the vector perpendicular to the nearest surface (as to travel the minimum distance). My criteria are efficiency and to some extend simplicity.

So my question is: which algorithm should I use to determine the Point and Time of Impact for a collision between possibly concave polygons and/or spheres that each have their own translation vector and rotation around a point (both of which could be 0).

One way is to calculate the impact time between a moving point and a moving line. This formula calculates just that. Apos, Bpos, Cpos = position of points A, B, C Avel, Bvel, Cvel = velocity of points A, B, C

    float A1x = Apos.x - Cpos.x;
    float A1y = Apos.y - Cpos.y;
    float B1x = Bpos.x - Cpos.x;
    float B1y = Bpos.y - Cpos.y;
    float Avx = Avel.x - Cvel.x;
    float Avy = Avel.y - Cvel.y;
    float Bvx = Bvel.x - Cvel.x;
    float Bvy = Bvel.y - Cvel.y;
    float t = (MathF.Sqrt(MathF.Pow(A1y * Bvx + B1x * Avy - B1y * Avx - Bvy * A1x, 2) - 4f * (A1y * B1x - B1y * A1x) * (Avy * Bvx - Bvy * Avx)) - A1y * Bvx - B1x * Avy + B1y * Avx + Bvy * A1x) / (2 * Avy * Bvx - 2 * Bvy * Avx);
    float t1 = -(MathF.Sqrt(MathF.Pow(A1y * Bvx + B1x * Avy - B1y * Avx - Bvy * A1x, 2) - 4f * (A1y * B1x - B1y * A1x) * (Avy * Bvx - Bvy * Avx)) + A1y * Bvx + B1x * Avy - B1y * Avx - Bvy * A1x) / (2 * Avy * Bvx - 2 * Bvy * Avx);

For this calculation, the velocity and position of point C is subtracted from A and B so the formula actually calculates the collision time between a moving line and the origin. The collision of the point C could happen on the axis passing by AB but outside the segment AB, have to do an extra check for that. The formula returns two values t and t1 that can be negative or NaN, have to check which one makes sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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