Novel iterative algorithm for determining optimal beam profiles in a 3-D space