![]() |
|
![]() |
| For what it's worth, Haskell's built-in sort does this, and I think Python, too. (But I'm not as confident about Python. My memory is a bit hazy.) |
![]() |
| I think your method seems useful for scenes that are mostly static. the "recreate the graph" approach seems better the more dynamic things are. |
![]() |
| objects are unlikely to jump from one side the screen to the other so comparing them to stuff on the other side of the screen seems like a waste (which is what a generic sort will do). |
![]() |
| You're right that it's not exactly n^2. For the i-th element we perform (n - i - 1) comparisons (indexing from 0). This adds up to a total of (n - 1) * n / 2 comparisons. (see https://en.wikipedia.org/wiki/Triangular_number)
In the end it doesn't make a difference for big-O analysis because it's used to describe the behavior when n approaches infinity, where the quadratic factor takes over. |
![]() |
| it's the summation of numbers from 1 to n which is n(n+1)/2. This reduces to quadratic complexity because big O notation ignores all coefficients and terms that scale slower |
![]() |
| I hadn't seen this before, but isn't it similar to using something like a quad-tree to reduce the number of potential colliders? |
![]() |
| This is awesome, very beautiful and well written!
Are there other handy 2-d algorithms that are this well explained? I know redblobgames has a treasure trove too, but curious about more. |
![]() |
| Excellent article. Sorting the list is a really simple and neat idea, without the need for clustering or a special data structure. |
![]() |
| Capsule-capsule overlap can be detected by treating the capsules as line segments with radius/thickness.
But I think you need something more complicated than capsule-capsule intersection to truly solve the problem (continuous collision detection between dynamic objects).
The Rapier project and its documentation[0] might be of interest to you. Rapier has a more sophisticated CCD implementation than most (popular in gamedev) physics engines. > Rapier implements nonlinear CCD, meaning that it takes into account both the angular and translational motion of the rigid-body. [0] https://rapier.rs/docs/user_guides/rust/rigid_bodies#continu... |
![]() |
| For fine collision between capsules, you consider the capsules as 3d segments with thickness. And two of those collide if the distance between segments
You can check this site with nice animations which explain how to compute the distance between segments : https://zalo.github.io/blog/closest-point-between-segments/ One more generic way to compute the distance between shapes is to view it as a minimization problem. You take a point A inside object 1 and a point B inside object 2, and you minimize the squared distance between the points : ||A-B||^2 while constraining point A to object 1 and point B to object 2. In the case of capsules, this is a "convex" optimization problem : So one way of solving for the points, is to take a minimization (newton) step and then project back each point to its respective convex object (projection is well defined and unique because of the convex property) (It usually need less than 10 iterations). In geometry, we often decompose object into convex unions. One example is sphere-trees, where you cover your object with spheres. This allow you to use fast coarse collision algorithm for spheres to find collision candidates of your capsules : You cover your capsules with spheres (a little bigger than the thickness) so that the capsule is inside the union of the spheres. |
![]() |
| Isn’t it just a matter of checking if two lines’ perigee fall within radius sum, and if so check if the respective segments’ closest points to the perigee are within radius sum? |
![]() |
| Super interesting, my first thought before I read the article was why not a bloom filter but didn’t expect it to be “physical” collision |
The reason is that objects in collision detection systems tend to move relatively small steps between frames, meaning you can keep lists from the previous frame that are already mostly sorted. For sorting these mostly sorted lists, insertion sort tends towards O(n) while Quicksort tends towards O(n^2)!