# include # include # include # include # include # include # include "polygon.h" 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 ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: polygon_test() tests polygon(). Licensing: This code is distributed under the MIT license. Modified: 17 December 2022 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "polygon_test():\n" ); printf ( " C version\n" ); printf ( " 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. */ printf ( "\n" ); printf ( "polygon_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ double f1 ( double x, double y ) /******************************************************************************/ /* 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; } /******************************************************************************/ double fx2 ( double x, double y ) /******************************************************************************/ /* 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; } /******************************************************************************/ void polygon_angles_test ( ) /******************************************************************************/ /* 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 }; printf ( "\n" ); printf ( "polygon_angles_test():\n" ); printf ( " polygon_angles() computes the angles of a polygon.\n" ); printf ( "\n" ); printf ( " Number of polygonal vertices = %d\n", n ); r8mat_transpose_print ( 2, n, v, " The polygon vertices:" ); angle = polygon_angles ( n, v ); printf ( "\n" ); printf ( " Polygonal angles in degrees:\n" ); printf ( "\n" ); for ( i = 0; i < n; i++ ) { printf ( " %8d %14.6g\n", i, r8_degrees ( angle[i] ) ); } free ( angle ); return; } /******************************************************************************/ void polygon_area_test ( ) /******************************************************************************/ /* 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 }; printf ( "\n" ); printf ( "polygon_area_test():\n" ); printf ( " polygon_area() computes the area of a polygon\n" ); printf ( " polygon_area_2() computes the area of a polygon\n" ); printf ( "\n" ); printf ( " Number of polygonal vertices = %d\n", n1 ); r8mat_transpose_print ( 2, n1, v1, " The polygon vertices:" ); area1 = polygon_area ( n1, v1 ); area2 = polygon_area_2 ( n1, v1 ); printf ( "\n" ); printf ( " Exact area is %g\n", area_exact1 ); printf ( " polygon_area() is %g\n", area1 ); printf ( " polygon_area_2() is %g\n", area2 ); printf ( "\n" ); printf ( " Number of polygonal vertices = %d\n", n2 ); r8mat_transpose_print ( 2, n2, v2, " The polygon vertices:" ); area1 = polygon_area ( n2, v2 ); area2 = polygon_area_2 ( n2, v2 ); printf ( "\n" ); printf ( " Exact area is %g\n", area_exact2 ); printf ( " polygon_area() is %g\n", area1 ); printf ( " polygon_area_2() is %g\n", area2 ); return; } /******************************************************************************/ void polygon_area_lattice_test ( ) /******************************************************************************/ /* Purpose: polygon_area_lattice_test() tests polygon_area_lattice(). Licensing: This code is distributed under the MIT license. Modified: 28 April 2022 Author: John Burkardt */ { double area; int b; int i; printf ( "\n" ); printf ( "polygon_area_lattice_test()\n" ); printf ( " polygon_area_lattice() returns the area\n" ); printf ( " of a polygon, measured in lattice points.\n" ); i = 5; b = 6; printf ( "\n" ); printf ( " Number of interior lattice points = %d\n", i ); printf ( " Number of boundary lattice points = %d\n", b ); area = polygon_area_lattice ( i, b ); printf ( " Area of polygon is %g\n", area ); return; } /******************************************************************************/ void polygon_centroid_test ( ) /******************************************************************************/ /* Purpose: polygon_centroid_test() tests polygon_centroid*(). Licensing: This code is distributed under the MIT license. Modified: 29 April 2022 Author: John Burkardt */ { double *centroid1; double *centroid2; int n = 4; double v[2*4] = { 1.0, 0.0, 2.0, 1.0, 1.0, 2.0, 0.0, 1.0 }; printf ( "\n" ); printf ( "polygon_centroid_test():\n" ); printf ( " polygon_centroid() computes the centroid of a polygon\n" ); printf ( " polygon_centroid_2() computes the centroid of a polygon\n" ); r8mat_transpose_print ( 2, n, v, " The polygon vertices:" ); centroid1 = polygon_centroid ( n, v ); r8vec_print ( 2, centroid1, " polygon_centroid():" ); centroid2 = polygon_centroid_2 ( n, v ); r8vec_print ( 2, centroid2, " polygon_centroid_2():" ); free ( centroid1 ); free ( centroid2 ); return; } /******************************************************************************/ void polygon_contains_point_test ( ) /******************************************************************************/ /* Purpose: polygon_contains_point_test() tests polygon_contains_point(). Licensing: This code is distributed under the MIT license. Modified: 28 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 }; printf ( "\n" ); printf ( "polygon_contains_point_test():\n" ); printf ( " polygon_contains_point() determines if a point is in a polygon.\n" ); printf ( " polygon_contains_point_2() determines if a point is in a polygon.\n" ); r8mat_transpose_print ( 2, n, v, " The polygon vertices:" ); printf ( "\n" ); printf ( " P In1 In2\n" ); printf ( "\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 ); printf ( " %14.6g %14.6g %d %d\n", p[0], p[1], inside1, inside2 ); } return; } /******************************************************************************/ void polygon_data_test ( ) /******************************************************************************/ /* Purpose: polygon_data_test() tests polygon_data_*(). Licensing: This code is distributed under the MIT license. Modified: 28 April 2022 Author: John Burkardt */ { double area; int n; double radin; double radout; double side; printf ( "\n" ); printf ( "polygon_data_test():\n" ); printf ( " Regular polygon data is area, inradius, outradius, side length.\n" ); printf ( " polygon_data_inrad() uses the inradius to compute the rest.\n" ); printf ( " polygon_data_outrad() uses the outradius to compute the rest.\n" ); printf ( " polygon_data_side() uses the side length to compute the rest.\n" ); side = 1; for ( n = 3; n <= 5; n++ ) { printf ( "\n" ); printf ( " Number of polygonal sides = %d\n", n ); side = 1.0; polygon_data_side ( n, side, &area, &radin, &radout ); printf ( "\n" ); printf ( " AREA = %g\n", area ); printf ( " RADIN = %g\n", radin ); printf ( " RADOUT = %g\n", radout ); printf ( " SIDE = %g (given)\n", side ); polygon_data_inrad ( n, radin, &area, &radout, &side ); printf ( "\n" ); printf ( " AREA = %g\n", area ); printf ( " RADIN = %g (given)\n", radin ); printf ( " RADOUT = %g\n", radout ); printf ( " SIDE = %g\n", side ); polygon_data_outrad ( n, radout, &area, &radin, &side ); printf ( "\n" ); printf ( " AREA = %g\n", area ); printf ( " RADIN = %g\n", radin ); printf ( " RADOUT = %g (given)\n", radout ); printf ( " SIDE = %g\n", side ); } return; } /******************************************************************************/ void polygon_diameter_test ( ) /******************************************************************************/ /* 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 }; printf ( "\n" ); printf ( "polygon_diameter_test():\n" ); printf ( " polygon_diameter() computes the diameter of a polygon;\n" ); r8mat_transpose_print ( 2, n, v, " The polygon vertices:" ); diameter = polygon_diameter ( n, v ); printf ( "\n" ); printf ( " Diameter ( computed ) %g\n", diameter ); printf ( " Diameter ( exact ) %g\n", diameter_exact ); return; } /******************************************************************************/ void polygon_expand_test ( ) /******************************************************************************/ /* 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; printf ( "\n" ); printf ( "polygon_expand_test():\n" ); printf ( " polygon_expand() expands a polygon by an amount H.\n" ); h = 0.5; r8mat_transpose_print ( 2, n, v, " The polygon vertices:" ); printf ( "\n" ); printf ( " The expansion amount H = %g\n", h ); w = polygon_expand ( n, v, h ); r8mat_transpose_print ( 2, n, w, " The expanded polygon:" ); free ( w ); return; } /******************************************************************************/ void polygon_integral_test ( ) /******************************************************************************/ /* Purpose: polygon_integral_test() tests polygon_integral_*(). Licensing: This code is distributed under the MIT license. Modified: 14 October 2015 Author: John Burkardt */ { int n = 3; double result; double v[2*3] = { 1.0, 1.0, 4.0, 3.0, 2.0, 5.0 }; printf ( "\n" ); printf ( "polygon_integral_test():\n" ); printf ( " polygon_integral_1() integrates 1 over a polygon\n" ); printf ( " polygon_integral_x() integrates x over a polygon\n" ); printf ( " polygon_integral_y() integrates y over a polygon\n" ); printf ( " polygon_integral_xx() integrates x^2 over a polygon\n" ); printf ( " polygon_integral_xy() integrates xy over a polygon\n" ); printf ( " polygon_integral_yy() integrates y^2 over a polygon\n" ); r8mat_transpose_print ( 2, n, v, " Vertices of polygon V:" ); printf ( "\n" ); result = polygon_integral_1 ( n, v ); printf ( " 1 %g\n", result ); result = polygon_integral_x ( n, v ); printf ( " X %g\n", result ); result = polygon_integral_y ( n, v ); printf ( " Y %g\n", result ); result = polygon_integral_xx ( n, v ); printf ( " X^2 %g\n", result ); result = polygon_integral_xy ( n, v ); printf ( " XY %g\n", result ); result = polygon_integral_yy ( n, v ); printf ( " Y^2 %g\n", result ); return; } /******************************************************************************/ void polygon_is_ccw_test ( ) /******************************************************************************/ /* 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 }; printf ( "\n" ); printf ( "polygon_is_ccw_test():\n" ); printf ( " polygon_is_cc2() determines if the vertices of a polygon\n" ); printf ( " 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 ) { printf ( " The polygon vertices are counter clockwise.\n" ); } else { printf ( " The polygon vertices are NOT counter clockwise.\n" ); } } return; } /******************************************************************************/ void polygon_is_convex_test ( ) /******************************************************************************/ /* 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; char title[255]; 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 }; printf ( "\n" ); printf ( "polygon_is_convex_test():\n" ); printf ( " polygon_is_convex() determines if a polygon is convex.\n" ); for ( test = 1; test <= test_num; test++ ) { if ( test == 1 ) { n = n01; v = v01; strcpy ( title, " A point:" ); } else if ( test == 2 ) { n = n02; v = v02; strcpy ( title, " A line:" ); } else if ( test == 3 ) { n = n03; v = v03; strcpy ( title, " A triangle:" ); } else if ( test == 4 ) { n = n04; v = v04; strcpy ( title, " A CCW triangle:" ); } else if ( test == 5 ) { n = n05; v = v05; strcpy ( title, " A CW triangle:" ); } else if ( test == 6 ) { n = n06; v = v06; strcpy ( title, " Polygon with large angle:" ); } else if ( test == 7 ) { n = n07; v = v07; strcpy ( title, " Polygon with huge angle:" ); } else if ( test == 8 ) { n = n08; v08 = ( double * ) malloc ( 2 * n * sizeof ( double ) ); 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; strcpy ( title, " A five-pointed star:" ); } else if ( test == 9 ) { n = n09; v09 = ( double * ) malloc ( 2 * n * sizeof ( double ) ); 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; strcpy ( title, " A hexagon:" ); } else if ( test == 10 ) { n = n10; v = v10; strcpy ( title, " A triangle twice:" ); } else if ( test == 11 ) { n = n11; v = v11; strcpy ( title, " Square knot:" ); } r8mat_transpose_print ( 2, n, v, title ); result = polygon_is_convex ( n, v ); if ( result == -1 ) { printf ( " The polygon is not convex.\n" ); } else if ( result == 0 ) { printf ( " The polygon is degenerate and convex.\n" ); } else if ( result == 1 ) { printf ( " The polygon is convex and counterclockwise.\n" ); } else if ( result == 2 ) { printf ( " The polygon is convex and clockwise.\n" ); } } free ( v08 ); free ( v09 ); return; } /******************************************************************************/ void polygon_perimeter_test ( ) /******************************************************************************/ /* Purpose: polygon_perimeter_test() tests polygon_perimeter(). Licensing: This code is distributed under the MIT license. Modified: 15 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 }; printf ( "\n" ); printf ( "polygon_perimeter_test():\n" ); printf ( " polygon_perimeter() computes the perimeter of a polygon\n" ); r8mat_transpose_print ( 2, n1, v1, " Vertices of polygon V1:" ); result = polygon_perimeter ( n1, v1 ); printf ( "\n" ); printf ( " Perimeter = %g\n", result ); r8mat_transpose_print ( 2, n2, v2, " Vertices of polygon V2:" ); result = polygon_perimeter ( n2, v2 ); printf ( "\n" ); printf ( " Perimeter = %g\n", result ); return; } /******************************************************************************/ void polygon_perimeter_quad_test ( ) /******************************************************************************/ /* 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; printf ( "\n" ); printf ( "polygon_perimeter_quad_test():\n" ); printf ( " polygon_perimeter_quad() estimates the integral of\n" ); printf ( " a function over the perimeter of a polygon using\n" ); printf ( " 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 ); printf ( "\n" ); printf ( " Using HMAX = %g, estimated integral of 1 over perimeter = %g\n", hmax, value ); printf ( "\n" ); hmax = 2.0; for ( i = 1; i <= 3; i++ ) { hmax = hmax / 2.0; value = polygon_perimeter_quad ( n1, v1, hmax, fx2 ); printf ( " Using HMAX = %g, estimated integral of x^2 over perimeter = %g\n", hmax, value ); } r8mat_transpose_print ( 2, n2, v2, " Vertices of polygon V2:" ); hmax = 0.5; value = polygon_perimeter_quad ( n2, v2, hmax, f1 ); printf ( "\n" ); printf ( " Using HMAX = %g, estimated integral of 1 over perimeter = %g\n", hmax, value ); printf ( "\n" ); hmax = 2.0; for ( i = 1; i <= 3; i++ ) { hmax = hmax / 2.0; value = polygon_perimeter_quad ( n2, v2, hmax, fx2 ); printf ( " Using HMAX = %g, estimated integral of x^2 over perimeter = %g\n", hmax, value ); } return; } /******************************************************************************/ void polygon_point_dist_test ( ) /******************************************************************************/ /* 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; printf ( "\n" ); printf ( "polygon_point_dist_test():\n" ); printf ( " polygon_point_dist() computes polygon-point distance.\n" ); r8mat_transpose_print ( 2, n, v, " Vertices of polygon:" ); printf ( "\n" ); printf ( " X Y DIST\n" ); printf ( "\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 ); printf ( " %14.6g %14.6g %14.6g\n", p[0], p[1], dist ); } return; } /******************************************************************************/ void polygon_point_near_test ( ) /******************************************************************************/ /* 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; printf ( "\n" ); printf ( "polygon_point_near_test():\n" ); printf ( " polygon_point_near() computes nearest point on polygon.\n" ); r8mat_transpose_print ( 2, n, v, " Vertices of polygon:" ); printf ( "\n" ); printf ( " X Y XN YN\n" ); printf ( "\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 ); printf ( " %14.6g %14.6g %14.6g %14.6g\n", p[0], p[1], pn[0], pn[1] ); free ( pn ); } return; } /******************************************************************************/ void polygon_sample_test ( ) /******************************************************************************/ /* 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; printf ( "\n" ); printf ( "polygon_sample_test():\n" ); printf ( " polygon_sample() samples a polygon.\n" ); seed = 123456789; x = polygon_sample ( nv, v, n, &seed ); r8mat_transpose_print ( 2, n, x, " Sample points:" ); free ( x ); return; } /******************************************************************************/ void polygon_triangulate_test ( ) /******************************************************************************/ /* 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: 13 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 }; printf ( "\n" ); printf ( "polygon_triangulate_test():\n" ); printf ( " polygon_triangulate() triangulates a polygon.\n" ); printf ( " Here, we triangulate the comb_10 polygon.\n" ); triangles = polygon_triangulate ( n, x, y ); printf ( "\n" ); printf ( " Triangles:\n" ); printf ( "\n" ); for ( j = 0; j < n - 2; j++ ) { printf ( " %2d: %2d %2d %2d\n", j, triangles[0+j*3], triangles[1+j*3], triangles[2+j*3] ); } free ( triangles ); return; }