Distance between orthocenter and circumcenter of a right | Java program for the above approach ; Function to calculate Euclidean distance between the points p1 and p2 ; Stores x coordinates of both points ; Stores y coordinates of both points ; Return the Euclid distance using distance formula ; Function to find orthocenter of the right angled triangle ; Find the length of the three sides ; Orthocenter will be the vertex opposite to the largest side ; Function to find the circumcenter of right angle triangle ; Circumcenter will be located at center of hypotenuse ; If AB is the hypotenuse ; If BC is the hypotenuse ; If AC is the hypotenuse ; Function to find distance between orthocenter and circumcenter ; Find circumcenter ; Find orthocenter ; Find the distance between the orthocenter and circumcenter ; Print distance between orthocenter and circumcenter ; Driver Code ; Given coordinates A , B , and C ; Function Call
import java . util . * ; class GFG { static class pair { double first , second ; public pair ( double first , double second ) { this . first = first ; this . second = second ; } } static double distance ( pair p1 , pair p2 ) { double x1 = p1 . first , x2 = p2 . first ; double y1 = p1 . second , y2 = p2 . second ; return Math . sqrt ( Math . pow ( x2 - x1 , 2 ) + Math . pow ( y2 - y1 , 2 ) * 1.0 ) ; } static pair find_orthocenter ( pair A , pair B , pair C ) { double AB = distance ( A , B ) ; double BC = distance ( B , C ) ; double CA = distance ( C , A ) ; if ( AB > BC && AB > CA ) return C ; if ( BC > AB && BC > CA ) return A ; return B ; } static pair find_circumcenter ( pair A , pair B , pair C ) { double AB = distance ( A , B ) ; double BC = distance ( B , C ) ; double CA = distance ( C , A ) ; if ( AB > BC && AB > CA ) return new pair ( ( A . first + B . first ) / 2 , ( A . second + B . second ) / 2 ) ; if ( BC > AB && BC > CA ) return new pair ( ( B . first + C . first ) / 2 , ( B . second + C . second ) / 2 ) ; return new pair ( ( C . first + A . first ) / 2 , ( C . second + A . second ) / 2 ) ; } static void findDistance ( pair A , pair B , pair C ) { pair circumcenter = find_circumcenter ( A , B , C ) ; pair orthocenter = find_orthocenter ( A , B , C ) ; double distance_between = distance ( circumcenter , orthocenter ) ; System . out . print ( distance_between + "NEW_LINE"); } public static void main ( String [ ] args ) { pair A , B , C ; A = new pair ( 0.0 , 0.0 ) ; B = new pair ( 6.0 , 0.0 ) ; C = new pair ( 0.0 , 8.0 ) ; findDistance ( A , B , C ) ; } }