Skip to main content

InCircle

Returns true if a point is inside a circle using distance.


Ryan Baumann
(theguywhogoton)
I noticed PyGame has no way in checking if a point is inside a circle or any distance function. I then created this, you can just import it (If you download the pyc file and place it in the folder of your game). distance(p1, p2) - Returns an integer check(dis, rad) - Returns a boolean Example: http://PhoenixProgramming.org/files/InCircleExample.py

Links

Home Page
http://www.pygame.org/

Releases

InCircle 1.0 — 25 Jan, 2009

Pygame.org account Comments

  • Ian Christen 2012-09-03 05:38:09

    def isInCircle(p1,r,p2): if radius < ((p1.x - p2.x)**2 +
    (p1.y - p2.y) **2)**.5:
    return True
    return False

    tada!

    Learn to Pythagoras...

    For checking if a rect is inside a circle:

    def rectInCircle(rect, circPoint, circRad):
    pointsIn = sum([isInCircle(circPoint, circRad, point)*1 for point in [rect.topleft, rect.topright, rect.bottomright, rect.bottomleft])

    #####you can return like this#####
    if pointsIn == 0:
    return 0 #all points out
    elif pointsIn == 4:
    return 1 #all points in
    return 2 #some points in

    #####or simply like this#####

    return pointsIn