Mathematics, a mixture of geometry and trigonometry.
First, calculate the length of the line segment between P(x,y) and P1(x1,y1). This would be done using geometry. Once this has been obtained, it is possible to formulate a right angled triangle using the x and y axis. This can be used to obtain the angle that the movement will procede at. This is done using trigonometry. Once this angle has been obtained, then make a right angled triangle with hypotenuse of length 5, starting at P(x,y) and calculate the length of the adjacent and opposite. It is pretty straight forward.
Just remember that the formula for the length of a stright line is sqrt((x2 - x1)^2 + (y2 - y1)^2). Because they are on the axis, the horizontal side of the triangle that will be made between P(x,y) and P1(x1,y1) will be x1-x, and the vertical side will be y1 - y. If there is any issues picturing this, just draw it out on a piece of paper.