Distance between orthocenter and circumcenter of a right | 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
function distance ( p1 , p2 ) { var x1 = p1 [ 0 ] , x2 = p2 [ 0 ] ; var y1 = p1 [ 1 ] , y2 = p2 [ 1 ] ; return Math . sqrt ( Math . pow ( x2 - x1 , 2 ) + Math . pow ( y2 - y1 , 2 ) * 1.0 ) ; } function find_orthocenter ( A , B , C ) { var AB = distance ( A , B ) ; var BC = distance ( B , C ) ; var CA = distance ( C , A ) ; if ( AB > BC && AB > CA ) return C ; if ( BC > AB && BC > CA ) return A ; return B ; } function find_circumcenter ( A , B , C ) { var AB = distance ( A , B ) ; var BC = distance ( B , C ) ; var CA = distance ( C , A ) ; if ( AB > BC && AB > CA ) return [ Math . floor ( ( A [ 0 ] + B [ 0 ] ) / 2 ) , Math . floor ( ( A [ 1 ] + B [ 1 ] ) / 2 ) ] ; if ( BC > AB && BC > CA ) return [ Math . floor ( ( B [ 0 ] + C [ 0 ] ) / 2 ) , Math . floor ( ( B [ 1 ] + C [ 1 ] ) / 2 ) ] ; return [ Math . floor ( ( C [ 0 ] + A [ 0 ] ) / 2 ) , Math . floor ( ( C [ 1 ] + A [ 1 ] ) / 2 ) ] ; } function findDistance ( A , B , C ) { circumcenter = find_circumcenter ( A , B , C ) ; orthocenter = find_orthocenter ( A , B , C ) ; var distance_between = distance ( circumcenter , orthocenter ) ; document . write ( distance_between + " " ) ; } var A , B , C ; A = [ 0 , 0 ] ; B = [ 6 , 0 ] ; C = [ 0 , 8 ] ; findDistance ( A , B , C ) ;