function [x,y,z]=toECEF(lat,lon,depth,degrees)

    c_wgs84_a = 6378137.0;
    c_wgs84_e2 = 0.00669437999013;
 
    if nargin<4
        degrees=true;
    end

    if degrees 
        lat = deg2rad(lat);
        lon = deg2rad(lon);
    end

    cos_lat = cos(lat);
    sin_lat = sin(lat);
    cos_lon = cos(lon);
    sin_lon = sin(lon);
 
    rn = computeRn(lat);
 
    x = (rn - depth) * cos_lat * cos_lon;
    y = (rn - depth) * cos_lat * sin_lon;
    z = (((1.0 - c_wgs84_e2) * rn) - depth) * sin_lat;
