Find maximum and minimum distance between magnets | Python 3 program for max and min distance ; Function for finding distance between pivots ; Function for minimum distance ; Function for maximum distance ; Drivers code
import math NEW_LINE def pivotDis ( x0 , y0 , x1 , y1 ) : NEW_LINE INDENT return math . sqrt ( ( x1 - x0 ) * ( x1 - x0 ) + ( y1 - y0 ) * ( y1 - y0 ) ) NEW_LINE DEDENT def minDis ( D , r1 , r2 ) : NEW_LINE INDENT return max ( ( D - r1 - r2 ) , 0 ) NEW_LINE DEDENT def maxDis ( D , r1 , r2 ) : NEW_LINE INDENT return D + r1 + r2 NEW_LINE DEDENT x0 = 0 NEW_LINE y0 = 0 NEW_LINE x1 = 8 NEW_LINE y1 = 0 NEW_LINE r1 = 4 NEW_LINE r2 = 5 NEW_LINE D = pivotDis ( x0 , y0 , x1 , y1 ) NEW_LINE print ( " Distance ▁ while ▁ repulsion ▁ = ▁ " , int ( maxDis ( D , r1 , r2 ) ) ) NEW_LINE print ( " Distance ▁ while ▁ attraction ▁ = ▁ " , minDis ( D , r1 , r2 ) ) NEW_LINE