Skip to content

Error within check collision #492

@hlucca

Description

@hlucca

Issue description

If you simulate paticles at high speed (using a bigger step), some particles will "catch" others. The reason is, the collision -correction does not take in account the fact, that paricles may overlap.

URL(s) of affected page(s)

https://processing.org/examples/circlecollision.html

Proposed fix

A workaraound may be: first re-place colliding particles back to their effective collding position (just the touching point). Approximatley like this (does works but is not perfectly realistic):

instaed of: (original code from othe example, bus the same)

  public void checkCollisionWith (Particle other) {
    // get distances between the particles
    PVector distanceVect = PVector.sub(other.position, position);
    // calculate magnitude of the vector separating the particle
    float istDistance = distanceVect.mag();
    float minDistance = radius + other.radius;
    if (istDistance < minDistance) {
      // ...there must be a collsion, if both are 2D circles
     // get angle of bVect
      float theta  = distanceVect.heading();
      ...     

DO THIS:

     // ...
     public void checkCollisionWith (Particle other) {
       // get distances between the particles
       PVector distanceVect = PVector.sub(other.position, position);
       // calculate magnitude of the vector separating the particle
       float istDistance = distanceVect.mag();
       float minDistance = radius + other.radius;
       if (istDistance < minDistance) {
          // first replace paricles: (NEW!)
         float distanceCorrection = (minDistance-istDistance)/2.0f;
         PVector correctionVector = distanceVect.normalize().mult(distanceCorrection);
         other.position.add(correctionVector);
         position.sub(correctionVector);
    
         // ...there must be a collsion, if both are 2D circles
         // get angle of bVect
         float theta  = distanceVect.heading();
         ...

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions