How to get 3D coordinates from distance, azimuth and elevation

青春壹個敷衍的年華 提交于 2021-01-29 17:56:57

问题


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


回答1:


close to get solution:

let azim = Math.atan( dx / dy ); // keep result in radians
let elev = Math.asin( dz / dist );

 X = Math.round( dist * ( Math.cos( elev ) * Math.sin( azim ) ) );
 Y = Math.round( dist * ( Math.cos( elev ) * Math.cos( azim ) ) );
 Z = Math.round( dist * Math.sin( elev ) );

Last prob to solve: in some cases (i.e X negative and ax lower than Math.abs(X) ) X and Y are wrong. Instead of coding conditions (if/else...) I'm now looking for a way to obtain directly the right results.



来源:https://stackoverflow.com/questions/57955036/how-to-get-3d-coordinates-from-distance-azimuth-and-elevation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!