# include # include # include # include # include # include using namespace std; # include "polygon.hpp" int main ( ); double f1 ( double x, double y ); double fx2 ( double x, double y ); void polygon_angles_test ( ); void polygon_area_test ( ); void polygon_area_lattice_test ( ); void polygon_centroid_test ( ); void polygon_contains_point_test ( ); void polygon_data_test ( ); void polygon_diameter_test ( ); void polygon_expand_test ( ); void polygon_integral_test ( ); void polygon_is_ccw_test ( ); void polygon_is_convex_test ( ); void polygon_perimeter_test ( ); void polygon_perimeter_quad_test ( ); void polygon_point_dist_test ( ); void polygon_point_near_test ( ); void polygon_sample_test ( ); void polygon_triangulate_test ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // polygon_test() tests polygon(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 17 December 2022 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "polygon_test():\n"; cout << " C++ version\n"; cout << " Test polygon().\n"; polygon_angles_test ( ); polygon_area_test ( ); polygon_area_lattice_test ( ); polygon_centroid_test ( ); polygon_contains_point_test ( ); polygon_data_test ( ); polygon_diameter_test ( ); polygon_expand_test ( ); polygon_integral_test ( ); polygon_is_ccw_test ( ); polygon_is_convex_test ( ); polygon_perimeter_test ( ); polygon_perimeter_quad_test ( ); polygon_point_dist_test ( ); polygon_point_near_test ( ); polygon_sample_test ( ); polygon_triangulate_test ( ); // // Terminate. // cout << "\n"; cout << "polygon_test():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 double f1 ( double x, double y ) //****************************************************************************80 // // Purpose: // // f1() evaluates f(x,y) = 1. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 20 October 2015 // // Author: // // John Burkardt // { double value; value = 1.0; return value; } //****************************************************************************80 double fx2 ( double x, double y ) //****************************************************************************80 // // Purpose: // // fx2() evaluates f(x,y) = x^2. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 20 October 2015 // // Author: // // John Burkardt // { double value; value = x * x; return value; } //****************************************************************************80 void polygon_angles_test ( ) //****************************************************************************80 // // Purpose: // // polygon_angles_test() tests polygon_angles(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 14 October 2015 // // Author: // // John Burkardt // { double *angle; int i; int n = 6; double v[2*6] = { 0.0, 0.0, 1.0, 0.0, 2.0, 1.0, 3.0, 0.0, 3.0, 2.0, 1.0, 2.0 }; cout << "\n"; cout << "polygon_angles_test():\n"; cout << " polygon_angles() computes the angles of a polygon.\n"; cout << "\n"; cout << " Number of polygonal vertices = " << n << "\n"; r8mat_transpose_print ( 2, n, v, " The polygon vertices:" ); angle = polygon_angles ( n, v ); cout << "\n"; cout << " Polygonal angles in degrees:\n"; cout << "\n"; for ( i = 0; i < n; i++ ) { cout << setw(8) << i << " " << setw(14) << r8_degrees ( angle[i] ) << "\n"; } delete [] angle; return; } //****************************************************************************80 void polygon_area_test ( ) //****************************************************************************80 // // Purpose: // // polygon_area_test() tests polygon_area(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 29 April 2022 // // Author: // // John Burkardt // { double area1; double area2; double area_exact1 = 2.0; double area_exact2 = 6.0; int n1 = 4; int n2 = 8; double v1[2*4] = { 1.0, 0.0, 2.0, 1.0, 1.0, 2.0, 0.0, 1.0 }; double v2[2*8] = { 0.0, 0.0, 3.0, 0.0, 3.0, 3.0, 2.0, 3.0, 2.0, 1.0, 1.0, 1.0, 1.0, 2.0, 0.0, 2.0 }; cout << "\n"; cout << "polygon_area_test():\n"; cout << " polygon_area() computes the area of a polygon.\n"; cout << "\n"; cout << " Number of polygonal vertices = " << n1 << "\n"; r8mat_transpose_print ( 2, n1, v1, " The polygon vertices:" ); area1 = polygon_area ( n1, v1 ); area2 = polygon_area_2 ( n1, v1 ); cout << "\n"; cout << " Exact area is " << area_exact1 << "\n"; cout << " polygon_area() " << area1 << "\n"; cout << " polygon_area_2() " << area2 << "\n"; cout << "\n"; cout << " Number of polygonal vertices = " << n2 << "\n"; r8mat_transpose_print ( 2, n2, v2, " The polygon vertices:" ); area1 = polygon_area ( n2, v2 ); area2 = polygon_area_2 ( n2, v2 ); cout << "\n"; cout << " Exact area is " << area_exact2 << "\n"; cout << " polygon_area() " << area1 << "\n"; cout << " polygon_area_2() " << area2 << "\n"; return; } //****************************************************************************80 void polygon_area_lattice_test ( ) //****************************************************************************80 // // Purpose: // // polygon_area_lattice_test() tests polygon_area_lattice(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 29 April 2022 // // Author: // // John Burkardt // { double area; int b; int i; cout << "\n"; cout << "polygon_area_lattice_test():\n"; cout << " polygon_area_lattice() returns the area\n"; cout << " of a polygon, measured in lattice points.\n"; i = 5; b = 6; cout << "\n"; cout << " Number of interior lattice points = " << i << "\n"; cout << " Number of boundary lattice points = " << b << "\n"; area = polygon_area_lattice ( i, b ); cout << " Lattice area of polygon is " << area << "\n"; return; } //****************************************************************************80 void polygon_centroid_test ( ) //****************************************************************************80 // // Purpose: // // polygon_centroid_test() tests polygon_centroid(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 14 October 2015 // // Author: // // John Burkardt // { double *centroid; int n = 4; double v[2*4] = { 1.0, 0.0, 2.0, 1.0, 1.0, 2.0, 0.0, 1.0 }; cout << "\n"; cout << "polygon_centroid_test():\n"; cout << " polygon_centroid() computes the centroid of a polygon.\n"; cout << " polygon_centroid_2() computes the centroid of a polygon.\n"; r8mat_transpose_print ( 2, n, v, " The polygon vertices:" ); centroid = polygon_centroid ( n, v ); r8vec_print ( 2, centroid, " polygon_centroid():" ); delete [] centroid; centroid = polygon_centroid_2 ( n, v ); r8vec_print ( 2, centroid, " polygon_centroid_2():" ); delete [] centroid; return; } //****************************************************************************80 void polygon_contains_point_test ( ) //****************************************************************************80 // // Purpose: // // polygon_contains_point_test() tests polygon_contains_point_*(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 29 April 2022 // // Author: // // John Burkardt // { int inside1; int inside2; int n = 5; double p[2]; double p_test[2*4] = { 1.0, 1.0, 3.0, 4.0, 0.0, 2.0, 0.5, -0.25 }; int test; int test_num = 4; double v[2*5] = { 0.0, 0.0, 1.0, 0.0, 2.0, 1.0, 1.0, 2.0, 0.0, 2.0 }; cout << "\n"; cout << "polygon_contains_point_test():\n"; cout << " polygon_contains_point() determines if a point is in a polygon.\n"; cout << " polygon_contains_point_2() determines if a point is in a polygon.\n"; r8mat_transpose_print ( 2, n, v, " The polygon vertices:" ); cout << "\n"; cout << " P Inside1 Inside2\n"; cout << "\n"; for ( test = 0; test < test_num; test++ ) { p[0] = p_test[0+test*2]; p[1] = p_test[1+test*2]; inside1 = polygon_contains_point ( n, v, p ); inside2 = polygon_contains_point_2 ( n, v, p ); cout << " "<< setw(14) << p[0] << " "<< setw(14) << p[1] << " "<< setw(1) << inside1 << " "<< setw(1) << inside2 << "\n"; } return; } //****************************************************************************80 void polygon_data_test ( ) //****************************************************************************80 // // Purpose: // // polygon_data_test() tests polygon_data_*(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 29 April 2022 // // Author: // // John Burkardt // { double area; int n; double radin; double radout; double side; cout << "\n"; cout << "polygon_data_test():\n"; cout << " polygon_data_inrad() uses the inradius to describe a regular polygon.\n"; cout << " polygon_data_outrad() uses the outradius to describe a regular polygon.\n"; cout << " polygon_data_side() uses the side to describe a regular polygon.\n"; for ( n = 3; n <= 5; n++ ) { cout << "\n"; cout << " Number of polygonal sides = " << n << "\n"; side = 1.0; polygon_data_side ( n, side, area, radin, radout ); cout << "\n"; cout << " AREA = " << area << "\n"; cout << " RADIN = " << radin << "\n"; cout << " RADOUT = " << radout << "\n"; cout << " SIDE = " << side << " (given)\n"; polygon_data_inrad ( n, radin, area, radout, side ); cout << "\n"; cout << " AREA = " << area << "\n"; cout << " RADIN = " << radin << " (given)\n"; cout << " RADOUT = " << radout << "\n"; cout << " SIDE = " << side << "\n"; polygon_data_outrad ( n, radout, area, radin, side ); cout << "\n"; cout << " AREA = " << area << "\n"; cout << " RADIN = " << radin << "\n"; cout << " RADOUT = " << radout << " (given)\n"; cout << " SIDE = " << side << "\n"; } return; } //****************************************************************************80 void polygon_diameter_test ( ) //****************************************************************************80 // // Purpose: // // polygon_diameter_test() tests polygon_diameter(); // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 14 October 2015 // // Author: // // John Burkardt // { double diameter; double diameter_exact = 2.0; int n = 4; double v[2*4] = { 1.0, 0.0, 2.0, 1.0, 1.0, 2.0, 0.0, 1.0 }; cout << "\n"; cout << "polygon_diameter_test():\n"; cout << " polygon_diameter() computes the diameter of a polygon.\n"; r8mat_transpose_print ( 2, n, v, " The polygon vertices:" ); diameter = polygon_diameter ( n, v ); cout << "\n"; cout << " Diameter ( computed ) " << diameter << "\n"; cout << " Diameter ( exact ) " << diameter_exact << "\n"; return; } //****************************************************************************80 void polygon_expand_test ( ) //****************************************************************************80 // // Purpose: // // polygon_expand_test() tests polygon_expand(); // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 14 October 2015 // // Author: // // John Burkardt // { double h; int n = 4; double v[2*4] = { 1.0, 1.0, 5.0, 1.0, 2.0, 4.0, 1.0, 3.0 }; double *w; cout << "\n"; cout << "polgon_expand_test():\n"; cout << " polygon_expand() expands a polygon by an amount H.\n"; h = 0.5; r8mat_transpose_print ( 2, n, v, " The polygon vertices:" ); cout << "\n"; cout << " The expansion amount H = " << h << "\n"; w = polygon_expand ( n, v, h ); r8mat_transpose_print ( 2, n, w, " The expanded polygon:" ); delete [] w; return; } //****************************************************************************80 void polygon_integral_test ( ) //****************************************************************************80 // // Purpose: // // polygon_integral_test() tests polygon_integral_*(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 29 April 2022 // // Author: // // John Burkardt // { int n = 3; double result; double v[2*3] = { 1.0, 1.0, 4.0, 3.0, 2.0, 5.0 }; cout << "\n"; cout << "polygon_integral_test():\n"; cout << " polygon_integral_1() integrates 1 over a polygon.\n"; cout << " polygon_integral_x() integrates x over a polygon.\n"; cout << " polygon_integral_xx() integrates x^2 over a polygon.\n"; cout << " polygon_integral_xy() integrates xy over a polygon.\n"; cout << " polygon_integral_yy() integrates y^2 over a polygon.\n"; r8mat_transpose_print ( 2, n, v, " The polygon vertices:" ); cout << "\n"; result = polygon_integral_1 ( n, v ); cout << " 1 " << result << "\n"; result = polygon_integral_x ( n, v ); cout << " x " << result << "\n"; result = polygon_integral_y ( n, v ); cout << " y " << result << "\n"; result = polygon_integral_xx ( n, v ); cout << " xx " << result << "\n"; result = polygon_integral_xy ( n, v ); cout << " xy " << result << "\n"; result = polygon_integral_yy ( n, v ); cout << " yy " << result << "\n"; return; } //****************************************************************************80 void polygon_is_ccw_test ( ) //****************************************************************************80 // // Purpose: // // polygon_is_ccw_test() tests polygon_is_ccw(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 17 December 2022 // // Author: // // John Burkardt // { int n = 4; int test; double *v; bool value; double vabcd[2*4] = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 }; double vabdc[2*4] = { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0 }; double vacbd[2*4] = { 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0 }; double vacdb[2*4] = { 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0 }; double vadbc[2*4] = { 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0 }; double vadcb[2*4] = { 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0 }; cout << "\n"; cout << "polygon_is_ccw_test():\n"; cout << " polygon_is_cc2() determines if the vertices of a polygon\n"; cout << " are listed in counter-clockwise order.\n"; // // Try all six orientations of the the four vertices. // Only one (a,b,c,d) should be acceptable. // for ( test = 1; test <= 6; test++ ) { if ( test == 1 ) { v = vabcd; } else if ( test == 2 ) { v = vabdc; } else if ( test == 3 ) { v = vacbd; } else if ( test == 4 ) { v = vacdb; } else if ( test == 5 ) { v = vadbc; } else if ( test == 6 ) { v = vadcb; } r8mat_transpose_print ( 2, n, v, " polygon vertices:" ); value = polygon_is_ccw ( n, v ); if ( value ) { cout << " The polygon vertices are counter clockwise.\n"; } else { cout << " The polygon vertices are NOT counter clockwise.\n"; } } return; } //****************************************************************************80 void polygon_is_convex_test ( ) //****************************************************************************80 // // Purpose: // // polygon_is_convex_test() tests polygon_is_convex(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 14 October 2015 // // Author: // // John Burkardt // { double angle; int i; int n; int n01 = 1; int n02 = 2; int n03 = 3; int n04 = 3; int n05 = 3; int n06 = 4; int n07 = 5; int n08 = 5; int n09 = 6; int n10 = 6; int n11 = 8; const double r8_pi = 3.141592653589793; int result; int test; int test_num = 11; string title; double *v; double v01[2*1] = { 0.0, 0.0 }; double v02[2*2] = { 0.0, 0.0, 1.0, 2.0 }; double v03[2*3] = { 0.0, 0.0, 2.0, 0.0, 1.0, 0.0 }; double v04[2*3] = { 0.0, 0.0, 1.0, 0.0, 0.0, 2.0 }; double v05[2*3] = { 0.0, 0.0, 0.0, 2.0, 1.0, 0.0 }; double v06[2*4] = { 1.0, 0.0, 2.0, 0.0, 3.0, 1.0, 0.0, 1.0 }; double v07[2*5] = { 0.0, 0.0, 0.5, 0.5, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 }; double *v08; double *v09; double v10[2*6] = { 0.0, 0.0, 2.0, 0.0, 1.0, 1.0, 0.0, 0.0, 2.0, 0.0, 1.0, 1.0 }; double v11[2*8] = { 1.0, 0.0, 3.0, 0.0, 3.0, 3.0, 0.0, 3.0, 0.0, 1.0, 2.0, 1.0, 2.0, 2.0, 1.0, 2.0 }; cout << "\n"; cout << "polygon_is_convex_test():\n"; cout << " polygon_is_convex() determines if a polygon is convex.\n"; for ( test = 1; test <= test_num; test++ ) { if ( test == 1 ) { n = n01; v = v01; title = " A point:"; } else if ( test == 2 ) { n = n02; v = v02; title = " A line:"; } else if ( test == 3 ) { n = n03; v = v03; title = " A triangle:"; } else if ( test == 4 ) { n = n04; v = v04; title = " A CCW triangle:"; } else if ( test == 5 ) { n = n05; v = v05; title = " A CW triangle:"; } else if ( test == 6 ) { n = n06; v = v06; title = " Polygon with large angle:"; } else if ( test == 7 ) { n = n07; v = v07; title = " Polygon with huge angle:"; } else if ( test == 8 ) { n = n08; v08 = new double[2*n]; for ( i = 0; i < n; i++ ) { angle = ( double ) ( i ) * 4.0 * r8_pi / ( double ) ( n ); v08[0+i*2] = cos ( angle ); v08[1+i*2] = sin ( angle ); } v = v08; title = " A five-pointed star:"; } else if ( test == 9 ) { n = n09; v09 = new double[2*n]; for ( i = 0; i < n; i++ ) { angle = ( double ) ( i ) * 2.0 * r8_pi / ( double ) ( n ); v09[0+i*2] = cos ( angle ); v09[1+i*2] = sin ( angle ); } v = v09; title = " A hexagon:"; } else if ( test == 10 ) { n = n10; v = v10; title = " A triangle twice:"; } else if ( test == 11 ) { n = n11; v = v11; title = " Square knot:"; } r8mat_transpose_print ( 2, n, v, title ); result = polygon_is_convex ( n, v ); if ( result == -1 ) { cout << " The polygon is not convex.\n"; } else if ( result == 0 ) { cout << " The polygon is degenerate and convex.\n"; } else if ( result == 1 ) { cout << " The polygon is convex and counterclockwise.\n"; } else if ( result == 2 ) { cout << " The polygon is convex and clockwise.\n"; } } delete [] v08; delete [] v09; return; } //****************************************************************************80 void polygon_perimeter_test ( ) //****************************************************************************80 // // Purpose: // // polygon_perimeter_test() tests polygon_perimeter(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 October 2015 // // Author: // // John Burkardt // { int n1 = 4; int n2 = 3; double result; double v1[2*4] = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 }; double v2[2*3] = { 1.0, 1.0, 4.0, 3.0, 2.0, 5.0 }; cout << "\n"; cout << "polygon_perimeter_test():\n"; cout << " polygon_perimeter() computes the perimeter of a polygon\n"; r8mat_transpose_print ( 2, n1, v1, " Vertices of polygon V1:" ); result = polygon_perimeter ( n1, v1 ); cout << "\n"; cout << " Perimeter = " << result << "\n"; r8mat_transpose_print ( 2, n2, v2, " Vertices of polygon V2:" ); result = polygon_perimeter ( n2, v2 ); cout << "\n"; cout << " Perimeter = " << result << "\n"; return; } //****************************************************************************80 void polygon_perimeter_quad_test ( ) //****************************************************************************80 // // Purpose: // // polygon_perimeter_quad_test() tests polygon_perimeter_quad(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 20 October 2015 // // Author: // // John Burkardt // { double hmax; int i; int n1 = 4; int n2 = 3; double v1[2*4] = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 }; double v2[2*3] = { 1.0, 1.0, 4.0, 3.0, 2.0, 5.0 }; double value; cout << "\n"; cout << "polygon_perimeter_quad_test():\n"; cout << " polygon_perimeter_quad() estimates the integral of\n"; cout << " a function over the perimeter of a polygon using\n"; cout << " the composite midpoint rule over each side.\n"; r8mat_transpose_print ( 2, n1, v1, " Vertices of polygon V1:" ); hmax = 0.5; value = polygon_perimeter_quad ( n1, v1, hmax, f1 ); cout << "\n"; cout << " Using HMAX = " << hmax << ", estimated integral of 1 over perimeter = " << value << "\n"; cout << "\n"; hmax = 2.0; for ( i = 1; i <= 3; i++ ) { hmax = hmax / 2.0; value = polygon_perimeter_quad ( n1, v1, hmax, fx2 ); cout << " Using HMAX = " << hmax << ", estimated integral of x^2 over perimeter = " << value << "\n"; } r8mat_transpose_print ( 2, n2, v2, " Vertices of polygon V2:" ); hmax = 0.5; value = polygon_perimeter_quad ( n2, v2, hmax, f1 ); cout << "\n"; cout << " Using HMAX = " << hmax << ", estimated integral of 1 over perimeter = " << value << "\n"; cout << "\n"; hmax = 2.0; for ( i = 1; i <= 3; i++ ) { hmax = hmax / 2.0; value = polygon_perimeter_quad ( n2, v2, hmax, fx2 ); cout << " Using HMAX = " << hmax << ", estimated integral of x^2 over perimeter = " << value << "\n"; } return; } //****************************************************************************80 void polygon_point_dist_test ( ) //****************************************************************************80 // // Purpose: // // polygon_point_dist_test() tests polygon_point_dist(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 14 October 2015 // // Author: // // John Burkardt // { double dist; int n = 3; double p[2]; double p_test[2*3] = { 4.0, 5.0, 2.0, 3.0, -2.0, -1.0 }; double v[2*3] = { 1.0, 1.0, 4.0, 3.0, 2.0, 5.0 }; int test; cout << "\n"; cout << "polygon_point_dist_test():\n"; cout << " polygon_point_dist() computes polygon-point distance.\n"; r8mat_transpose_print ( 2, n, v, " Vertices of polygon:" ); cout << "\n"; cout << " X Y DIST\n"; cout << "\n"; for ( test = 0; test < 3; test++ ) { p[0] = p_test[0+test*2]; p[1] = p_test[1+test*2]; dist = polygon_point_dist ( n, v, p ); cout << " " << setw(14) << p[0] << " " << setw(14) << p[1] << " " << setw(14) << dist << "\n"; } return; } //****************************************************************************80 void polygon_point_near_test ( ) //****************************************************************************80 // // Purpose: // // polygon_point_near_test() tests polygon_point_near(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 14 October 2015 // // Author: // // John Burkardt // { int n = 3; double p[2]; double p_test[2*3] = { 4.0, 5.0, 2.0, 3.0, -2.0, -1.0 }; double *pn; double v[2*3] = { 1.0, 1.0, 4.0, 3.0, 2.0, 5.0 }; int test; cout << "\n"; cout << "polygon_point_near_test():\n"; cout << " polygon_point_near() computes nearest point on polygon.\n"; r8mat_transpose_print ( 2, n, v, " Vertices of polygon:" ); cout << "\n"; cout << " X Y XN YN\n"; cout << "\n"; for ( test = 0; test < 3; test++ ) { p[0] = p_test[0+test*2]; p[1] = p_test[1+test*2]; pn = polygon_point_near ( n, v, p ); cout << " " << setw(14) << p[0] << " " << setw(14) << p[1] << " " << setw(14) << pn[0] << " " << setw(14) << pn[1] << "\n"; delete [] pn; } return; } //****************************************************************************80 void polygon_sample_test ( ) //****************************************************************************80 // // Purpose: // // polygon_sample_test() tests polygon_sample(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 14 October 2015 // // Author: // // John Burkardt // { int n = 20; int nv = 6; int seed; double v[2*6] = { 0.0, 0.0, 2.0, 0.0, 2.0, 1.0, 1.0, 1.0, 1.0, 2.0, 0.0, 1.0 }; double *x; cout << "\n"; cout << "polygon_sample_test():\n"; cout << " polygon_sample() samples a polygon.\n"; seed = 123456789; x = polygon_sample ( nv, v, n, seed ); r8mat_transpose_print ( 2, n, x, " Sample points:" ); delete [] x; return; } //****************************************************************************80 void polygon_triangulate_test ( ) //****************************************************************************80 // // Purpose: // // polygon_triangulate_test() tests polygon_triangulate(). // // Discussion: // // There are N-3 triangles in the triangulation. // // For the first N-2 triangles, the first edge listed is always an // internal diagonal. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 14 October 2015 // { int j; int n = 10; int *triangles; double x[10] = { 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0, 4.0 }; double y[10] = { 0.0, 10.0, 0.0, 10.0, 0.0, 10.0, 0.0, 10.0, 0.0, -2.0 }; cout << "\n"; cout << "polygon_triangulate_test():\n"; cout << " polygon_triangulate() triangulates a polygon.\n"; cout << " Here, we triangulate the comb_10 polygon.\n"; triangles = polygon_triangulate ( n, x, y ); cout << "\n"; cout << " Triangles:\n"; cout << "\n"; for ( j = 0; j < n - 2; j++ ) { cout << " " << setw(2) << j << ": " << " " << setw(2) << triangles[0+j*3] << " " << setw(2) << triangles[1+j*3] << " " << setw(2) << triangles[2+j*3] << "\n"; } delete [] triangles; return; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // timestamp() prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 08 July 2009 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }