Maximum distance between two points in coordinate plane using Rotating Caliper 's Method |  ; Function calculates distance between two points ; Function to find the maximum distance between any two points ; Iterate over all possible pairs ; Update maxm ; Return actual distance ; Driver Code ; Number of points ; Given points ; Function Call
from math import sqrt NEW_LINE def dist ( p1 , p2 ) : NEW_LINE INDENT x0 = p1 [ 0 ] - p2 [ 0 ] NEW_LINE y0 = p1 [ 1 ] - p2 [ 1 ] NEW_LINE return x0 * x0 + y0 * y0 NEW_LINE DEDENT def maxDist ( p ) : NEW_LINE INDENT n = len ( p ) NEW_LINE maxm = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT maxm = max ( maxm , dist ( p [ i ] , p [ j ] ) ) NEW_LINE DEDENT DEDENT return sqrt ( maxm ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 NEW_LINE p = [ ] NEW_LINE p . append ( [ 4 , 0 ] ) NEW_LINE p . append ( [ 0 , 2 ] ) NEW_LINE p . append ( [ - 1 , - 7 ] ) NEW_LINE p . append ( [ 1 , 10 ] ) NEW_LINE p . append ( [ 2 , - 3 ] ) NEW_LINE print ( maxDist ( p ) ) NEW_LINE DEDENT