(original) (raw)

function [ center, flag ] = triangle_orthocenter ( t ) %*****************************************************************************80 % %% triangle_orthocenter() computes the orthocenter of a triangle in 2D. % % Discussion: % % The orthocenter is defined as the intersection of the three altitudes % of a triangle. % % An altitude of a triangle is the line through a vertex of the triangle % and perpendicular to the opposite side. % % In geometry, the orthocenter of a triangle is often symbolized by "H". % % Licensing: % % This code is distributed under the MIT license. % % Modified: % % 29 July 2023 % % Author: % % John Burkardt % % Reference: % % Adrian Bowyer, John Woodwark, % A Programmer's Geometry, % Butterworths, 1983. % % Input: % % real T(3,2), the triangle vertices. % % Output: % % real CENTER(1,2), the orthocenter of the triangle. % % logical FLAG, is TRUE if the value could not be computed. % % % Determine a point P23 common to the line (P2,P3) and % its perpendicular through P1. % [ p23, flag ] = line_exp_perp_2d ( t(2,1:2), t(3,1:2), t(1,1:2) ); if ( flag ) center(1,1:2) = Inf; return end % % Determine a point P31 common to the line (P3,P1) and % its perpendicular through P2. % [ p31, flag ] = line_exp_perp_2d ( t(3,1:2), t(1,1:2), t(2,1:2) ); if ( flag ) center(1,1:2) = Inf; return end % % Determine CENTER, the intersection of the lines (P1,P23) and (P2,P31). % [ ival, center ] = lines_exp_int_2d ( t(1,1:2), p23(1,1:2), t(2,1:2), ... p31(1,1:2) ); if ( ival ~= 1 ) flag = 1; center(1,1:2) = Inf; return end return end