0

I have a little demo in Processing of circular repulsion. It works great except the moment when object and its repulsor (mouse) have degrees close to 360 | 0 zone (or PI | -PI ).

or YouTube video

It's 100% because of this transition, but I don't have any idea how to overcome it. Have already played with modulo.

SyntaxRules
  • 1,503
  • 19
  • 32
VVK
  • 325
  • 1
  • 15

2 Answers2

1

At first - I hope that you don't mix radians and degrees in comparisons.

Your calculation

 float angleDist = abs(angle - repulsor.angle);
   and later comparison with 
 inc=45 degrees

works wrong if one angle is 359 and and another is 1, for example.

You can build some if-conditions or use expression:

angleDist = arrcos(cos(angle - repulsor.angle)); 

that treats all cases correctly

MBo
  • 66,413
  • 3
  • 45
  • 68
0

It's inside object, Processing / JAVA, goes around 0.0, 0.0 center

      float repulsorAngle = atan2(repulsor.y, repulsor.x);
      if(rad < 0.0) { angle = map(rad, -PI, 0, 180, 360); }
      else { angle = map(rad, 0, PI, 0, 180);  }

      float angleDist = abs(angle - repulsor.angle);
      float dist = PVector.dist(new PVector(x, y), new PVector(repulsor.x, repulsor.y));

      float inc = 45.0;

      if (angleDist < inc) {
      float sine = sin(map(angleDist, inc, 0, 0, PI / 2)) * 50.0;

      println(sine);

      x = cos(radians(angle)) * (r + sine * dir);
      y = sin(radians(angle)) * (r + sine * dir);

      } else {

      x = cos(radians(angle)) * (r);
      y = sin(radians(angle)) * (r);

      }
VVK
  • 325
  • 1
  • 15