public double distance2 ( double [ ] point1 , double [ ] point2 ) throws Exception { if ( point1 . length == point2 . length ) { Double sum = 0D ; for ( int i = 0 ; i < point1 . length ; i ++ ) { double tmp = point2 [ i ] - point1 [ i ] ; sum = sum + tmp * tmp ; } return sum ; } else { throw new Exception ( "Exception in Euclidean distance: array lengths are not equal" ) ; } }
Calculates the square of the Euclidean distance between two multidimensional points represented by the rational vectors .