%%Prevedeni souradnicoveho systemu z ECEF do ENU
function [E,N,U] = ECEF2ENU (reflat,reflong,refh,X,Y,Z)

%prevedeni referencniho bodu z WGS84 do ECEF
[Xr,Yr,Zr]=WGS2ECEF(reflat, reflong, refh); 

%prevedeni na radiany
reflat=reflat*pi./180;
reflong=reflong*pi./180;

%vypocet
E=-(X-Xr).*sin(reflong)+(Y-Yr).*cos(reflong);
N=-(X-Xr).*sin(reflat).*cos(reflong)-(Y-Yr).*sin(reflat).*sin(reflong)+(Z-Zr).*cos(reflat);
U=(X-Xr).*cos(reflat).*cos(reflong)+(Y-Yr).*cos(reflat).*sin(reflong)+(Z-Zr).*sin(reflat);
end