/* Returns twice the signed area of the triangle determined by a,b,c. The area is positive if a,b,c are oriented ccw, negative if cw, and zero if the points are collinear. */ int Area2( tPointi a, tPointi b, tPointi c ) { return a[0] * b[1] - a[1] * b[0] + a[1] * c[0] - a[0] * c[1] + b[0] * c[1] - c[0] * b[1]; } /* Exclusive or: true iff exactly one argument is true. The arguments are negated to ensure that they are 0/1 values. Then the bitwise xor operator may apply. (This idea is due to Michael Baldwin.) */ bool xor( bool x, bool y ) { return !x ^ !y; } bool Left( tPointi a, tPointi b, tPointi c ) { return Area2( a, b, c ) > 0; } bool LeftOn( tPointi a, tPointi b, tPointi c ) { return Area2( a, b, c ) >= 0; } bool Collinear( tPointi a, tPointi b, tPointi c ) { return Area2( a, b, c ) == 0; } /* Puts a - b into c. */ void SubVec( tPointi a, tPointi b, tPointi c ) { int i; for( i = 0; i < DIM; i++ ) c[i] = a[i] - b[i]; } /* Returns the dot product of the two input vectors. */ int Dot( tPointi a, tPointi b ) { int i; int sum = 0; for( i = 0; i < DIM; i++ ) sum += sum + a[i] * b[i]; return sum; } /* Returns the square of the length of the vector p. */ int Length2( tPointi p ) { return Dot( p, p ); } /* Implements a = b, assignment of points/vectors. Assignment between arrays is not possible in C. */ void PointAssign( tPointi a, tPointi b ) { int i; for ( i = 0; i < DIM; i++ ) a[i] = b[i]; } void PrintPoint( tPointi p ) { int i; /* putchar('('); */ for ( i = 0; i < DIM; i++ ) { printf("%d", p[i]); if ( i != DIM-1 ) putchar(' '); } /* putchar(')'); */ } /* Reads in the coordinates of the vertices of a polygon from stdin, puts them into P, and returns n, the number of vertices. Formatting conventions: etc. */ int ReadPoly( tPolygoni P ) { int n = 0; /* printf("Polygon:\n"); */ /* printf(" i x y\n"); */ while ( (n < PMAX) && (scanf("%d %d",&P[n][0],&P[n][1]) != EOF) ) { /* printf("%3d%4d%4d\n", n, P[n][0], P[n][1]); */ ++n; } if (n < PMAX) /* printf("n = %3d vertices read\n",n)*/; else printf("Error in read_poly: too many points; max is %d\n", PMAX); /* putchar('\n'); */ return n; } void PrintPoly( int n, tPolygoni P ) { int i; /* printf("Polygon:\n");*/ /* printf(" i x y\n"); */ /* for( i = 0; i < n; i++ ) printf("%4d%4d\n", P[i][0], P[i][1]); */ }