Calculating ArcRotateCamera's Position from its Target

Please refer to the Playground link below of a third-person WASD-movement demo:

Please click inside the Playground scene to activate Pointer Lock. Pressing Esc will exit Pointer Lock.

  • Blue mesh is the player.
  • Red mesh is the camera’s target.
  • Green mesh is an obstacle with checkCollisions = true. The ground also has collision checking on.

I’m trying to calculate the ArcRotateCamera’s Position from its Target. Please refer the code under the comment // Attempt to calculate camera's position from target.

According to the dat.GUI, which has precision 0.000001, the calculated camera’s position is equal to its ground truth position. However, when I open Google Chrome’s console (Ctrl + Shift + I) and log the calculated camera’s position and its ground truth position, they are off slightly. Below is an example console.log:

camera ground truth position: {X: 2.7277877019953114 Y:5.182685911109842 Z:3.111219122006279}
camera calculated position: {X: 2.727787612232863 Y:5.182685971260071 Z:3.1112191307335486}

I’m confused why the calculated and ground truth positions are not equal at 7-decimal-point precision…

Thank you so much for your help! :smile:

Pinging @PolygonalSun

My guess would be that it is due to floating point precision in javascript :slight_smile:

absolutePosition is being calculated after a few transformation calculations, and your calculation is also processing vectors in different ways. and when this happens:


you can expect a slight lack of precision in floating point calculations.