Construct a closest point with 2 parameters

Hello! Can anybody give some ideas to solve this? I have a point O, and have an algorithm to construct another point P, and I want point P to be as close as possible to O. Now this algorithm involves 2 variables. How can I determine the values of the 2 variables respectively, so that I can get the desired point P? 

Hope this is clear enough to explain my problem. Thank you in advance for any help!