1
\$\begingroup\$

I have a physics problem to deal with, I am asking here because a game developers often uses the efficient method. I have randomly distributed circles interacting to through Lennard-Jones potential or simply with a bounce back boundary condition to wall of random shape, as of know I am taking a V shaped wall. Please help me to understand an efficient algorithm the game developers uses for bounce back interaction. x.periodic,y.wall

\$\endgroup\$
8
  • \$\begingroup\$ Presumably you started by doing research on the topics of collision-detection and collision-resolution before asking a new question, so that we don't need to re-hash material that can already be found elsewhere. Based on your research so far, what algorithm have you selected to try to implement? Where are you currently stuck in understanding or implementing it? \$\endgroup\$
    – DMGregory
    Mar 31 '19 at 11:15
  • \$\begingroup\$ Please see the video. "youtube.com/watch?v=-fq0Xpk1hoI&feature=youtu.be ".(simulation shown is for spheres, with little anomaly at 28 sec) So far I did the simulation of rods made up of spheres connected by springs and by bending force. When these rods hits the walls Bounce back pushes it back, I have done it. Now I am trying to place an arbitrary structure in simulation box , the rods are supposed to interact with the structure. Since the collision is head on, I will need perpendicular distance from structure but I don't understand to how to find it. \$\endgroup\$
    – user24234
    Mar 31 '19 at 12:00
  • \$\begingroup\$ So is your question "How to find the perpendicular distance between a circle and a line segment"? \$\endgroup\$
    – DMGregory
    Mar 31 '19 at 12:07
  • \$\begingroup\$ Not exactly sir. My doubt is to how to decide with which line segment of the object the sphere is going to interact with, as the blue object is made up of 6 line segments. Then the perpendicular is distance is fine. thanks \$\endgroup\$
    – user24234
    Mar 31 '19 at 12:14
  • \$\begingroup\$ Then it sounds like you're looking for a spatial partitioning strategy, that will help you narrow the list of possible closest objects to check against. What spatial partitions have you tried using so far? Where did you run into trouble putting them into practice here? \$\endgroup\$
    – DMGregory
    Mar 31 '19 at 12:37
0
\$\begingroup\$

First off, your wall definition should use a consistent counter-clockwise or clockwise vertex ordering.

This will properly define for each edge which side is 'inside' and which is 'outside.'

Let's assume counter-clockwise ordering: 'inside' is always left of the edge.

To find particle/wall collisions, you just test all edges of the walls, and reflect velocities if the particle is too close to the wall, or on the wrong side of the wall.

For low wall counts, say in the hundreds or less, it is perfectly fine to test each particle against all edges.

If the wall definition becomes too complex, you want to reduce the number of tests. This is done via spatial indexing.

The simplest form of spatially indexed world, is a uniform grid. Just list all walls present in each grid cell.

If the walls are very sparse, or range in sizes, you could consider a quad-tree instead.

To calculate whether a point is on the left or the right side of an edge, I use a 2d cross product, like so:

/* tells if vec c lies on the left side of directed edge a->b
 * 1 if left, -1 if right, 0 if colinear
 */
int left_of( cpVect a, cpVect b, cpVect c )
{
        const cpVect tmp1 = cpvsub( b, a );
        const cpVect tmp2 = cpvsub( c, b );
        const float x = cpvcross( tmp1, tmp2 );
        return x < 0 ? -1 : x > 0;
}

If you need to further accelerate the code, you should look into vectorized code via SIMD. You can test 8 particles against a single wall, or 8 walls against a single particle by using AVX vector instructions.

\$\endgroup\$
1
  • \$\begingroup\$ There is this kind of worst case event where the sphere comes right into the mouth of a concave element - basically right into the mouth of a V. It could turn into a pretty messy series of rapid bounces and jitter I imagine if you don't watch out. \$\endgroup\$
    – Tim Holt
    Apr 1 '19 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.