program main c*********************************************************************72 c cc triangle_analyze() determines properties of a triangle. c c Usage: c c triangle_analyze filename c c where "filename" is a file containing the coordinates of the vertices. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 20 August 2023 c c Author: c c John Burkardt c implicit none double precision angles(3) double precision area integer arg_num double precision centroid(2) double precision circum_center(2) double precision circum_radius integer dim_num double precision edge_length(3) logical flag integer iarg integer iargc double precision in_center(2) double precision in_radius character ( len = 255 ) node_filename integer node_num double precision node_xy(2,3) integer orientation double precision ortho_center(2) double precision quality double precision r8_pi parameter ( r8_pi = 3.141592653589793D+00 ) integer triangle_orientation call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'triangle_analyze():' write ( *, '(a)' ) ' FORTRAN77 version:' write ( *, '(a)' ) ' Analyze properties of a triangle whose' write ( *, '(a)' ) ' vertex coordinates are read from a file.' c c Get the number of command line arguments. c arg_num = iargc ( ) c c Commandline argument #1 is the file name c if ( 1 .le. arg_num ) then iarg = 1 call getarg ( iarg, node_filename ) else write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'triangle_analyze():' write ( *, '(a)' ) ' Enter name of the node coordinate file.' read ( *, '(a)' ) node_filename end if c c Read the node data. c call r8mat_header_read ( node_filename, dim_num, node_num ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) & ' Read header of "' // trim ( node_filename ) //'".' write ( *, '(a)' ) ' ' write ( *, '(a,i8)' ) ' Spatial dimension DIM_NUM = ', dim_num write ( *, '(a,i8)' ) ' Number of points NODE_NUM = ', node_num if ( dim_num .ne. 2 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'triangle_properties(): Fatal error!' write ( *, '(a)' ) ' Dataset must have spatial dimension 2.' stop 1 end if if ( node_num .ne. 3 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'triangle_properties(): Fatal error!' write ( *, '(a)' ) ' Dataset must have 3 nodes.' stop 1 end if call r8mat_data_read ( node_filename, dim_num, node_num, node_xy ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) & ' Read the data in "' // trim ( node_filename ) //'".' call r8mat_transpose_print ( dim_num, node_num, node_xy, & ' Node coordinates:' ) c c ANGLES c call triangle_angles ( node_xy, angles ) call r8vec_print ( 3, angles, ' ANGLES (radians):' ) angles(1:3) = angles(1:3) * 180.0D+00 / r8_pi call r8vec_print ( 3, angles, ' ANGLES (degrees):' ) c c AREA c call triangle_area ( node_xy, area ) write ( *, '(a)' ) ' ' write ( *, '(a,g14.6)' ) ' AREA: ', area c c CENTROID c call triangle_centroid ( node_xy, centroid ) write ( *, '(a)' ) ' ' write ( *, '(a,2g14.6)' ) ' CENTROID: ', centroid(1:2) c c CIRCUMCIRCLE c call triangle_circumcircle ( node_xy, circum_radius, & circum_center ) write ( *, '(a)' ) ' ' write ( *, '(a,g14.6)' ) ' CIRCUM_RADIUS: ', circum_radius write ( *, '(a,2g14.6)' ) ' CIRCUM_CENTER: ', circum_center(1:2) c c EDGE LENGTHS c call triangle_edge_length ( node_xy, edge_length ) call r8vec_print ( 3, edge_length, ' EDGE_LENGTHS:' ) c c INCIRCLE c call triangle_incircle ( node_xy, in_radius, in_center ) write ( *, '(a)' ) ' ' write ( *, '(a,g14.6)' ) ' IN_RADIUS: ', in_radius write ( *, '(a,2g14.6)' ) ' IN_CENTER: ', in_center(1:2) c c ORIENTATION c orientation = triangle_orientation ( node_xy ) write ( *, '(a)' ) ' ' if ( orientation .eq. 0 ) then write ( *, '(a,2g14.6)' ) ' ORIENTATION: CounterClockwise.' else if ( orientation .eq. 1 ) then write ( *, '(a,2g14.6)' ) ' ORIENTATION: Clockwise.' else if ( orientation .eq. 2 ) then write ( *, '(a,2g14.6)' ) & ' ORIENTATION: Degenerate Distinct Colinear Points.' else if ( orientation .eq. 3 ) then write ( *, '(a,2g14.6)' ) & ' ORIENTATION: Degenerate, at least two points identical.' end if c c ORTHOCENTER c call triangle_orthocenter ( node_xy, ortho_center, flag ) if ( flag ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' ORTHO_CENTER: Could not be computed.' else write ( *, '(a)' ) ' ' write ( *, '(a,2g14.6)' ) ' ORTHO_CENTER: ', ortho_center(1:2) end if c c QUALITY c call triangle_quality ( node_xy, quality ) write ( *, '(a)' ) ' ' write ( *, '(a,g14.6)' ) ' QUALITY: ', quality c c Terminate. c write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'triangle_analyze():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' call timestamp ( ) stop end