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
Jan 24, 2015

Jan 20, 2015



Jan 15, 2015

Jan 14, 2015


Jan 7, 2015

Jan 4, 2015


Dec 30, 2014

Dec 14, 2014

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