acircle.getCenter() to (x,y) coordinates in Python

G Yu neptinizer101 at gmail.com
Sat Dec 23 14:44:19 EST 2017


My program has two circles: one stationary circle, drawn at a random location; and one moving circle, consistently drawn in the same place in the graphics window.

The moving circle moves towards the stationary one.  However, when the moving circle hits the stationary one (when the x-coordinates of the circles' centers are equal), I want the moving circle to stop moving and then disappear.

I tried the command acircle.getCenter() to determine when the centers are equal, but it doesn't work; I suspect because the centers are never truly equal, and only come within something like .000001 pixels of each other.  So to account for the approximation, I used the math function "isclose":

move_moving_circle = True

    while move_moving_circle:
        moving_circle.move(P_to_R/P_to_E, E_to_R/P_to_E)
        time.sleep(0.01)

        if isclose(moving_circle.getCenter(), stationary_circle.getCenter(), rel_tol=1e-4, abs_tol=0.0):
            move_moving_circle= False

        else:
            move_moving_circle = True


But this doesn't work.  Apparently isclose can't be applied to points - only floating-point decimals.


So now, I want to convert the output of "acircle.getCenter()" to Cartesian (x,y) coordinates for both circles.  Then I can use the two circle centers' x-coordinates in the if statement.

Currently, acircle.getCenter() outputs this:

<graphics.Point object at 0x0000013E0D263668>
<graphics.Point object at 0x0000013E0D263B00>

I don't understand/can't use the format that the locations are printed in.

How do I convert the above format to "usable" Cartesian coordinates?  Or is there a simpler way to solve this problem?

Thanks!



More information about the Python-list mailing list