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 max ; Return actual distance ; Driver Code ; Number of points ; Given points ; Function Call
import java . awt . * ; import java . util . ArrayList ; public class Main { static long dist ( Point p1 , Point p2 ) { long x0 = p1 . x - p2 . x ; long y0 = p1 . y - p2 . y ; return x0 * x0 + y0 * y0 ; } static double maxDist ( Point p [ ] ) { int n = p . length ; double max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { max = Math . max ( max , dist ( p [ i ] , p [ j ] ) ) ; } } return Math . sqrt ( max ) ; } public static void main ( String [ ] args ) { int n = 5 ; Point p [ ] = new Point [ n ] ; p [ 0 ] = new Point ( 4 , 0 ) ; p [ 1 ] = new Point ( 0 , 2 ) ; p [ 2 ] = new Point ( - 1 , - 7 ) ; p [ 3 ] = new Point ( 1 , 10 ) ; p [ 4 ] = new Point ( 2 , - 3 ) ; System . out . println ( maxDist ( p ) ) ; } }