pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
Wiki

CalculateDist

      
Search:  
 
 

Get the distance between two (x,y) format locations using the Pythagorean theorem

In a right triangle, (x1-x2) being the horizontal distance between the two points (The change in x) and (y1-y2) being the vertical distance between the two points (The change in y),

(x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) == distance*distance. So the distance is the square root of (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2).

dist = math.sqrt((x1-x2)**2 + (y1-y2)**2))

You can also used the math function hypot:

dist = math.hypot(x1-x2, y1-y2)
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Nov 13, 2014

Nov 11, 2014


Nov 10, 2014

Nov 9, 2014

Nov 6, 2014


Nov 4, 2014

Nov 3, 2014

Oct 28, 2014

Oct 21, 2014

Oct 16, 2014

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)