Applying 2D algorithms for inverting the potential field data is more useful and efficient than their 3D counterparts, whenever the geologic situation permits. This is because the computation time is less and modeling the subsurface is easier. In this paper we present a 2D inversion algorithm for interpreting gravity data by employing a set of constraints including minimum distance, smoothness, and compactness. Using different combination of these constraints provide either smooth images of the underground geological structures or models with sharp geological boundaries. We model the study area by a large number of infinitely long horizontal prisms with square cross-sections and unknown densities. The final density distribution is obtained by minimizing an objective function that is composed of the model objective function and equality constraints, which are combined using a Lagrangian multipliers. Each block's weight depends on depth, a priori information on density and the allowed density ranges for the specified area. A MATLAB code has been developed and tested on a synthetic model consists of vertical and dipping dikes. The algorithm is applied with different combinations of constraints and the practical aspects are discussed. Results indicate that when a combination of constraints is used, the geometry and density distribution of both structures can be reconstructed. The method is applied on Zereshlu Mining Camp in Zanjan - Iran, which is well known for the Manganese ores. Result represents a high density distribution with the horizontal extension of about 30 m, and the vertical extension shows a trend in the E - W direction with a depth interval between 7 to 22 m in the east and 15 to 35 m in the west.