# include # include # include # include # include # include "ellipse.h" int main ( ); void ellipse_area1_test ( ); void ellipse_area2_test ( ); void ellipse_area3_test ( ); void ellipse_aspect_ratio_test ( ); void ellipse_eccentricity_test ( ); void ellipse_flattening_test ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: ellipse_test() tests ellipse(). Licensing: This code is distributed under the MIT license. Modified: 14 October 2022 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "ellipse_test():\n" ); printf ( " C version\n" ); printf ( " Test ellipse().\n" ); ellipse_area1_test ( ); ellipse_area2_test ( ); ellipse_area3_test ( ); ellipse_aspect_ratio_test ( ); ellipse_eccentricity_test ( ); ellipse_flattening_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "ellipse_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void ellipse_area1_test ( ) /******************************************************************************/ /* Purpose: ellipse_area1_test() tests ellipse_area1(). Licensing: This code is distributed under the MIT license. Modified: 07 April 2022 Author: John Burkardt */ { double a[2*2] = { 5.0, 1.0, 1.0, 2.0 }; double area; double r; printf ( "\n" ); printf ( "ellipse_area1_test():\n" ); printf ( " ellipse_area1() computes the area of an ellipse.\n" ); r = 10.0; area = ellipse_area1 ( a, r ); printf ( "\n" ); printf ( " R = %g\n", r ); printf ( "\n" ); printf ( " Matrix A in ellipse definition x*A*x=r^2:\n" ); printf ( " [ %g %g ]\n", a[0+0*2], a[0+1*2] ); printf ( " [ %g %g ]\n", a[1+1*2], a[1+1*2] ); printf ( " Area = %g\n", area ); return; } /******************************************************************************/ void ellipse_area2_test ( ) /******************************************************************************/ /* Purpose: ellipse_area2_test() tests ellipse_area2(). Licensing: This code is distributed under the MIT license. Modified: 08 November 2016 Author: John Burkardt */ { double a; double area; double b; double c; double d; printf ( "\n" ); printf ( "ellipse_area2_test():\n" ); printf ( " ellipse_area2() computes the area of an ellipse.\n" ); a = 5.0; b = 2.0; c = 2.0; d = 10.0; area = ellipse_area2 ( a, b, c, d ); printf ( "\n" ); printf ( " Ellipse: %g * x^2 + %g * xy + %g * y^2 = %g\n", a, b, c, d ); printf ( " Area = %g\n", area ); return; } /******************************************************************************/ void ellipse_area3_test ( ) /******************************************************************************/ /* Purpose: ellipse_area3_test() tests ellipse_area3(). Licensing: This code is distributed under the MIT license. Modified: 08 November 2016 Author: John Burkardt */ { double area; double r1; double r2; printf ( "\n" ); printf ( "ellipse_area3_test():\n" ); printf ( " ellipse_area3() computes the area of an ellipse.\n" ); r1 = 10.0; r2 = 10.0 / 3.0; area = ellipse_area3 ( r1, r2 ); printf ( "\n" ); printf ( " Ellipse: (x/%g)^2 + (y/%g)^2 = 1\n", r1, r2 ); printf ( " Area = %g\n", area ); return; } /******************************************************************************/ void ellipse_aspect_ratio_test ( ) /******************************************************************************/ /* Purpose: ellipse_aspect_ratio_test() tests ellipse_aspect_ratio(). Licensing: This code is distributed under the MIT license. Modified: 14 October 2022 Author: John Burkardt */ { double a; double b; double e; int i; int n; printf ( "\n" ); printf ( "ellipse_aspect_ratio_test():\n" ); printf ( " ellipse_aspect_ratio() computes the aspect ratio of an ellipse.\n" ); printf ( "\n" ); printf ( " A B Ratio\n" ); printf ( "\n" ); a = 1.0; n = 10; for ( i = 0; i <= n; i++ ) { b = ( double ) ( i ) / ( double ) ( n ); e = ellipse_aspect_ratio ( a, b ); printf ( " %5.1f %5.1f %10.6f\n", a, b, e ); } return; } /******************************************************************************/ void ellipse_eccentricity_test ( ) /******************************************************************************/ /* Purpose: ellipse_eccentricity_test() tests ellipse_eccentricity(). Licensing: This code is distributed under the MIT license. Modified: 24 March 2021 Author: John Burkardt */ { double a; double b; double e; int i; int n; printf ( "\n" ); printf ( "ellipse_eccentricity_test():\n" ); printf ( " ellipse_eccentricity() computes the eccentricity of an ellipse.\n" ); printf ( "\n" ); printf ( " A B Ecc\n" ); printf ( "\n" ); a = 1.0; n = 10; for ( i = 0; i <= n; i++ ) { b = ( double ) ( i ) / ( double ) ( n ); e = ellipse_eccentricity ( a, b ); printf ( " %5.1f %5.1f %10.6f\n", a, b, e ); } return; } /******************************************************************************/ void ellipse_flattening_test ( ) /******************************************************************************/ /* Purpose: ellipse_flattening_test() tests ellipse_flattening(). Licensing: This code is distributed under the MIT license. Modified: 14 October 2022 Author: John Burkardt */ { double a; double b; double e; int i; int n; printf ( "\n" ); printf ( "ellipse_flattening_test():\n" ); printf ( " ellipse_flattening() computes the flattening of an ellipse.\n" ); printf ( "\n" ); printf ( " A B Flat\n" ); printf ( "\n" ); a = 1.0; n = 10; for ( i = 0; i <= n; i++ ) { b = ( double ) ( i ) / ( double ) ( n ); e = ellipse_flattening ( a, b ); printf ( " %5.1f %5.1f %10.6f\n", a, b, e ); } return; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 01 May 2021 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }