A new tracking algorithm is proposed for threedimensional object tracking. It is based on an active contours algorithm with region-based minimization for twodimensional tracking. The algorithm is extended to use the sharpness of the objects enclosed by the contour to determine an estimate for the z position. This depth-from-defocus approach is enabled through different sharpness calculations, including the grey level variance and column-wise and row-wise variance calculation, which allow to analyze the astigmatism. By this, the ambiguity of the out-of-focus displacement is resolved. The algorithm can deliver estimates for the z position of an object if the object is in a certain range around the focal point, without relying on external assumptions. The characteristic of the defocusing is determined by executing a focus sweep and calculating the defocus curve for the object of interest. The ability of the algorithm to generate threedimensional position coordinates is evaluated in a setup with nanopositioners and the principal feasibility is shown.