Python @ DjangoSpin

PyPro #85 Calculate distance between points on Cartesian Plane

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Distance between points on Cartesian Plane in Python

Distance between points on Cartesian Plane in Python

Given two points represented by coordinates i.e. (x1, y1) & (x2, y2), write a Python program to calculate distance between points on Cartesian Plane. The distance is calculated as square root of summation of squares of difference between corresponding x and y values.

import math

pointOne = (3,0)
pointTwo = (0,4)

distanceBetweenPoints = math.sqrt(    ( (pointOne[0]-pointTwo[0]) ** 2 )    +    ( (pointOne[1]-pointTwo[1]) **2 )    )

print(distanceBetweenPoints)		# 5.0

See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply