roof-geodesy.mjs 760 B

1234567891011
  1. // Local WGS84 conversion for offline raster sampling. Matrix is column-major ENU -> ECEF.
  2. export function enuToGeodetic(transform, x, y, z) {
  3. const X = transform[0]*x + transform[4]*y + transform[8]*z + transform[12]
  4. const Y = transform[1]*x + transform[5]*y + transform[9]*z + transform[13]
  5. const Z = transform[2]*x + transform[6]*y + transform[10]*z + transform[14]
  6. const a = 6378137, e2 = 6.6943799901413165e-3, b = a*Math.sqrt(1-e2)
  7. const p = Math.hypot(X,Y), theta = Math.atan2(Z*a,p*b)
  8. const latitude = Math.atan2(Z + (a*a-b*b)/(b*b)*b*Math.sin(theta)**3, p-e2*a*Math.cos(theta)**3)
  9. const normal = a/Math.sqrt(1-e2*Math.sin(latitude)**2)
  10. return {longitude:Math.atan2(Y,X), latitude, height:p/Math.cos(latitude)-normal}
  11. }