(original) (raw)

function quality = triangle_quality ( t ) %*****************************************************************************80 % %% triangle_quality(): "quality" of a triangle in 2D. % % Discussion: % % The quality of a triangle is 2 times the ratio of the radius of the inscribed % circle divided by that of the circumscribed circle. An equilateral % triangle achieves the maximum possible quality of 1. % % 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 QUALITY, the quality of the triangle. % % % Compute the length of each side. % a = norm ( t(1,1:2) - t(2,1:2) ); b = norm ( t(2,1:2) - t(3,1:2) ); c = norm ( t(3,1:2) - t(1,1:2) ); if ( a * b * c == 0.0 ) quality = 0.0; else quality = ( - a + b + c ) * ( a - b + c ) * ( a + b - c ) / ( a * b * c ); end return end