How to find the vertical and horizontal distance from the center of a rectangle <p>For my current Java project I have to compute the horizontal and vertical distance from the center of a rectangle. I tried using the formula from a previous project to find such a distance. Here is my code:</p> <pre><code> // Calculations; centerCoordinate = 0 formula = Math.sqrt(Math.pow(userXCoordinate - centerCoordinate, 2) + Math.pow(userYCoordinate - centerCoordinate, 2)); </code></pre> <p>My professor gave the hint that a point is in the rectangle if its horizontal distance to (0, 0) is less than or equal to 10 / 2 and its vertical distance to (0, 0) is less than or equal to 5 / 2. I tried using 5 for horizontal distance and 2.5 for vertical distance and setting variables to these numbers. I then made an if-else loop saying if the result of the formula was less than or equal to the variables the coordinates were in the rectangle otherwise they were outside. This returned a wrong answer; what could I do differently? </p>