Page 1 of 1

### Couple of bugs found!!!

Posted: Mon Nov 23, 2015 12:09 am
Hello William,

while developing simulator I found couple of small bugs in dyn4j library

1. Rectangle class in Geometry package

Code: Select all

`/**    * Returns the rotation about the local center in radians.    * @return double the rotation in radians    * @since 3.0.1    */   public double getRotation() {      // when the shape is created normals[1] will always be the positive x-axis      // we can get the rotation by comparing it to the positive x-axis      // since the normal vectors are rotated with the vertices when      // a shape is rotated      // return this.normals[1].getAngleBetween(Vector2.X_AXIS); //original                    return -this.normals[1].getAngleBetween(Vector2.X_AXIS); //corrected   }`

2. Polygon Class in Geometry package

Code: Select all

` @Override   public void rotate(double theta, double x, double y) {      super.rotate(theta, x, y);      int size = this.vertices.length;      for (int i = 0; i < size; i++) {         this.vertices[i].rotate(theta, x, y);         // this.normals[i].rotate(theta, x,y);//original         this.normals[i].rotate(theta); //corrected==>normals are not supposed to be rotated about point      }   }`

These bugs create problem in multi-fixture body with fixture as rectangle rotated by some angle. The angle of rotation is then calculated about wrongly transformed normals.
Anyway Dyn4j is one of the best thing I learnt so far.
Regards..

### Re: Couple of bugs found!!!

Posted: Mon Nov 23, 2015 11:49 am
maheshkurmi wrote:return -this.normals[1].getAngleBetween(Vector2.X_AXIS); //original
return -this.normals[1].getAngleBetween(Vector2.X_AXIS); //corrected

I can't spot the difference

I'm sure William will appreciate a JUnit test case that can be included in the Dyn4J build if you have one.

### Re: Couple of bugs found!!!

Posted: Mon Nov 23, 2015 12:35 pm
Oh.. i am sorry ..
edited
Actually I have modified dyn4j library quite a lot according to my use, so it will be confusing to include some test cases. I was just trying to find out bug related to polygon
fixture rotation, while adding facility for copy/paste in my physics simulator, and I finally found out these errors as the culprits.

### Re: Couple of bugs found!!!

Posted: Mon Nov 23, 2015 1:11 pm
Thank you very much for these bug reports. Both are quite embarrassing since I was doing these the right way in some other shape classes....

I've fixed the code, added some JUnit tests, and generated a new jar if you'd like to do testing. I'll try to get this released as a new version on Maven asap.

William

### Re: Couple of bugs found!!!

Posted: Mon Nov 23, 2015 9:45 pm
A new version of dyn4j has been released with these fixes applied. Thanks again for reporting!

William