Andy R. answered • 06/16/19

Computer Engineer/CS Instructor with 13+ Years of Teaching Experience

Let's assume that the new position is M(x, y). If you consider P being the center of a circle with radius d, then M can be any point on this circle. The equation of this circle will be (x-0.3)^{2} + (y-0.5)^{2} = d^{2}. Then pick any random value for x, greater or equal to (0.3-d) and less or equal to (0.3+d). In this way, by using the above formula, you will be able to calculate the correct value for y, thus, the position of M. In C# the square root is Math.Sqrt().