Distance between orthocenter and circumcenter of a right | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; double distance ( pair < double , double > p1 , pair < double , double > p2 ) { double x1 = p1 . first , x2 = p2 . first ; double y1 = p1 . second , y2 = p2 . second ; return sqrt ( pow ( x2 - x1 , 2 ) + pow ( y2 - y1 , 2 ) * 1.0 ) ; } pair < double , double > find_orthocenter ( pair < double , double > A , pair < double , double > B , pair < double , double > 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 ; } pair < double , double > find_circumcenter ( pair < double , double > A , pair < double , double > B , pair < double , double > C ) { double AB = distance ( A , B ) ; double BC = distance ( B , C ) ; double CA = distance ( C , A ) ; if ( AB > BC && AB > CA ) return { ( A . first + B . first ) / 2 , ( A . second + B . second ) / 2 } ; if ( BC > AB && BC > CA ) return { ( B . first + C . first ) / 2 , ( B . second + C . second ) / 2 } ; return { ( C . first + A . first ) / 2 , ( C . second + A . second ) / 2 } ; } void findDistance ( pair < double , double > A , pair < double , double > B , pair < double , double > C ) { pair < double , double > circumcenter = find_circumcenter ( A , B , C ) ; pair < double , double > orthocenter = find_orthocenter ( A , B , C ) ; double distance_between = distance ( circumcenter , orthocenter ) ; cout << distance_between << endl ; } int main ( ) { pair < double , double > A , B , C ; A = { 0.0 , 0.0 } ; B = { 6.0 , 0.0 } ; C = { 0.0 , 8.0 } ; findDistance ( A , B , C ) ; return 0 ; }