I'm working in a 3D environment (a 100x100x100 virtual cube) where each point is defined by its x, y and z position. We have two points: A with position x:20 y:35 z:40 and B x:50 y:40 z:85. Using this algo (https://gis.stackexchange.com/questions/108547/how-to-calculate-distance-azimuth-and-dip-from-two-xyz-coordinates) I'm able to find the distance, the azimuth and the elevation of B seen from A.
let ax = 20;
let ay = 35;
let az = 40;
let bx = 50;
let by = 40;
let bz = 85;
let dx = bx-ax;
let dy = by-ay;
let dz = bz-az;
let dist = Math.sqrt( Math.pow(dx,2) + Math.pow(dy,2) + Math.pow(dz,2) ); // SQRT((x2–x1)2+(y2–y1)2+(z2–z1)2)
let azim = toDeg( Math.atan( dx / dy ) ); // arctan((x2–x1)/(y2–y1))
let elev = toDeg( Math.asin( dz / dist ) ); // arcsin ((z2–z1) / distance)
Azimuth+elevation are converted in degrees with the function toDeg() for verification
function toDeg (angle) {
let a = angle * (180 / Math.PI);
return a
}
The result:
dist = 54.31390245600108
azim = 80.53767779197439
elev = 55.94671404468539
The question is now: how to retrieve B initial values? Knowing the A pos (20,35,40) and dist+azim+elev of B, is it possible to obtain its position 50,40,85?
Supposing Math functions don't return the exact result (truncated decimals) an absolute precision is not important because finding i.e 49.9999 instead of 50 gives the correct value with Math.round() -> the point x:49.9999 y:40.0002 z:84,9999 doesn't exist in the cube.
Thx in advance for help