# Math Check: Distance Between 2 Obbjects

This topic is 2196 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I would like to knoow if my math is correct in calculating the distance between 2 objects on a 2D plain:
[CODE]def distance(x1,x2,y1,y2):
# A squared + B squared = C squared
return ( ( (x2 - x1)**2) + ( (y2-y1)**2) )**.5
# Object 1 Location
coordinate1 = 2,8 # x,y
# Object 2 Location
coordinate2 = 5,10 # x,y
print (distance(coordinate1[0],coordinate2[0],coordinate1[1],coordinate2[1]))[/CODE]

Thanks.

##### Share on other sites
[quote name='Shippou' timestamp='1326567700' post='4902719']
I would like to knoow if my math is correct in calculating the distance between 2 objects on a 2D plain:
[CODE]def distance(x1,x2,y1,y2):
# A squared + B squared = C squared
return ( ( (x2 - x1)**2) + ( (y2-y1)**2) )**.5
# Object 1 Location
coordinate1 = 2,8 # x,y
# Object 2 Location
coordinate2 = 5,10 # x,y
print (distance(coordinate1[0],coordinate2[0],coordinate1[1],coordinate2[1]))[/CODE]

Thanks.
[/quote]

Yes, that is correct.

-Josh

##### Share on other sites
yup. That distance equation will give you the distance between two points.

##### Share on other sites

Holy crap! Ninja'd twice!

Thank you.