I have two questions regarding the transformation of ECEF to ENU. My questions are expressed through the following two examples:
Lets say we have the point P0 as the origin of the ENU local reference frame.
- Shouldn’t the following transformation give the same results, such as those we get using the Matlab ecef2enu function in the link here? The results seem to be close, but they are not identical.
//Example #1: Comparison with ecef2enu Matlab function
const lon0 = 36.7484,//https://www.mathworks.com/help/map/ref/ecef2enu.html
lat0 = 45.9132,
h0 = 1877.7532,
P0 = new Cesium.Cartesian3.fromDegrees(lon0, lat0, h0*1e3);
const transform = Cesium.Transforms.eastNorthUpToFixedFrame(P0);//Transformation matrix for rotaions and translations for ENU
const transformInv = Cesium.Matrix4.inverse(transform, new Cesium.Matrix4());//The inverse transformation matrix
const x = 5507.5289,
y = 4556.2241,
z = 6012.8208,
PoI = new Cesium.Cartesian3(x*1e3, y*1e3, z*1e3);
const resMatlab = Cesium.Matrix4.multiplyByVector(transformInv , new Cesium.Cartesian4(PoI.x, PoI.y, PoI.z, 1), new Cesium.Cartesian4());//resMatlab is the coordinates of O in the ENU
console.log(`Example #1: The coordinates of resMatlab in the ENU are (in km) ${Cesium.Cartesian3.multiplyByScalar(resMatlab, 1e-3, new Cesium.Cartesian3())}, while Matlab ouput is (355.6013, -923.0832, 1.0410e+03)`);
- Let’s use the scaleToGeodeticSurface function to scale P0 downwards along the geodetic surface normal, so that P0 will be projected on the surface of the WGS84 ellipsoid as Ps. Then, we express Ps wrt the ENU reference system. Since the Up axis of ENU is perpendicular to the ellipsoid surface, it is expected that enuPs.x and enuPs.y should be zero. However, only enuPs.x = 0, while enuPs.y is not zero.
//Example #2: Normal projection on the surface of the WGS84 ellipsoid
const Ps = Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(P0, new Cesium.Cartesian3()); //The coordinates of Ps in the ECEF
const enuPs = Cesium.Matrix4.multiplyByVector(transformInv , new Cesium.Cartesian4(Ps.x, Ps.y, Ps.z, 1), new Cesium.Cartesian4());//enuPs is the coordinates of Ps in the ENU
console.log(`Example #2: The coordinates of Ps in the ENU are (in km): ${Cesium.Cartesian3.multiplyByScalar(enuPs, 1e-3, new Cesium.Cartesian3())}. N-axis should have been zero, but its not`);
Here is the corresponding sandcastle.
What am I missing?
Thanks!