calculating 3D coordinates improved