Three.js: rotateAround wrong result

Created on 11 Apr 2020  路  1Comment  路  Source: mrdoob/three.js

Description of the problem

The following code works:

new Vector2(100, 100).rotateAround(new Vector2(50, 50), MathUtils.degToRad(90))

and it returns:

Vector2聽{x: 0, y: 100}

The following also works:

new Vector2(10, 10).rotateAround(new Vector2(5, 5), MathUtils.degToRad(90))

and it returns:

Vector2聽{x: 0, y: 10}

But the following code...

new Vector2(1, 1).rotateAround(new Vector2(0.5, 0.5), MathUtils.degToRad(90))

...returns this:

Vector2聽{x: 5.551115123125783e-17, y: 1}

I believe it should return the following:

Vector2 { x: 0, y: 1 }

The version I'm using is ^0.115.0

Most helpful comment

What you see is an inaccuracy which is inevitable when computing with floating point. The issue is that Math.cos( Math.PI * 0.5 ) isn't actually 0 but 6.123233995736766e-17. Computing with this value leads to the reported result.

There is actually a stackoverflow thread about this topic:

https://stackoverflow.com/questions/8050722/math-cosmath-pi-2-returns-6-123031769111886e-17-in-javascript-as3

>All comments

What you see is an inaccuracy which is inevitable when computing with floating point. The issue is that Math.cos( Math.PI * 0.5 ) isn't actually 0 but 6.123233995736766e-17. Computing with this value leads to the reported result.

There is actually a stackoverflow thread about this topic:

https://stackoverflow.com/questions/8050722/math-cosmath-pi-2-returns-6-123031769111886e-17-in-javascript-as3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

konijn picture konijn  路  3Comments

makc picture makc  路  3Comments

jack-jun picture jack-jun  路  3Comments

boyravikumar picture boyravikumar  路  3Comments

clawconduce picture clawconduce  路  3Comments