/* * ====================================================================== * Test Polygon Functions * * Copyright (C) 1994-96 by Mark Austin and David Mazzoni. * * This software is provided "as is" without express or implied warranty. * Permission is granted to use this software on any computer system, * and to redistribute it freely, subject to the following restrictions: * * 1. The authors are not responsible for the consequences of use of * this software, even if they arise from defects in the software. * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * 4. This notice is to remain intact. * * Written by: M.A. Austin March, 1994 * ====================================================================== */ #include #include "polygon.h" /* Define vertex coordinates of exterior polygon and holes */ static float coord1[8][2] = {{ 1.0, 5.0}, {14.0, 5.0}, {14.0, 4.0}, {11.0, 4.0}, {11.0, 1.0}, { 4.0, 1.0}, { 4.0, 4.0}, { 1.0, 4.0}}; static float hole1 [4][2] = {{ 5.0, 4.0}, { 5.0, 2.0}, { 7.0, 2.0}, { 7.0, 4.0}}; static float hole2 [4][2] = {{ 8.0, 4.0}, { 8.0, 2.0}, {10.0, 2.0}, {10.0, 4.0}}; int main( void ) { POLYGON *spPolygon, *spHole1, *spHole2; EDGE *spEdge; double dArea, dI_xx, dI_yy, dI_xy; int ii; /* [a] : Create exterior polygon (clockwise orientation) */ spEdge = polyCreateEdge( coord1[0][0], coord1[0][1], 0.0 ); spPolygon = polyCreate("Polygon Exterior", spEdge ); for(ii = 1; ii < (sizeof(coord1)/(2*sizeof(coord1[0][0]))); ii = ii + 1) { spEdge = polyCreateEdge( coord1[ ii ][0], coord1[ ii ][1], 0.0 ); polyAddEdge( spPolygon, spEdge ); } /* [b] : Create hole 1 (anticlockwise orientation) */ spEdge = polyCreateEdge( hole1[0][0], hole1[0][1], 0.0 ); spHole1 = polyCreate("hole 1", spEdge ); for(ii = 1; ii < (sizeof(hole1)/(2*sizeof(hole1[0][0]))); ii = ii + 1) { spEdge = polyCreateEdge( hole1[ ii ][0], hole1[ ii ][1], 0.0 ); polyAddEdge( spHole1, spEdge ); } /* [c] : Create hole 2 (anticlockwise orientation) */ spEdge = polyCreateEdge( hole2[0][0], hole2[0][1], 0.0 ); spHole2 = polyCreate("hole 2", spEdge ); for(ii = 1; ii < (sizeof(hole2)/(2*sizeof(hole2[0][0]))); ii = ii + 1) { spEdge = polyCreateEdge( hole2[ ii ][0], hole2[ ii ][1], 0.0 ); polyAddEdge( spHole2, spEdge ); } /* [d] : Put holes 1 and 2 in polygon and print */ polyAddHole( spPolygon, spHole2 ); polyAddHole( spPolygon, spHole1 ); polyPrint( spPolygon ); /* [e] : Compute and print engineering properties */ dArea = polyProperty( polyPropertyArea, spPolygon ); dI_xx = polyProperty( polyPropertyIxx, spPolygon ); dI_yy = polyProperty( polyPropertyIyy, spPolygon ); dI_xy = polyProperty( polyPropertyIxy, spPolygon ); printf("\n\n"); printf("*** Engineering Properties : Area = %16.2f\n", dArea ); printf("*** : I_xx = %16.2f\n", dI_xx ); printf("*** : I_yy = %16.2f\n", dI_yy ); printf("*** : I_xy = %16.2f\n", dI_xy ); }