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
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:
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 actually0but6.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