#ifndef AST_CLASS #define AST_CLASS #include #include #include #include class ast { public: float x, y, xv, yv, theta; polygon p; bool inside (float, float, float); polygon cp (float); friend istream& operator >> (istream&, polygon &); friend ostream& operator << (ostream&, const ast &); }; polygon ast::cp (float t) { float a = xv * t + x, b = yv * t + y; while (a > 100) {a-=100;} while (a < 0) {a+=100;} while (b > 100) {b-=100;} while (b < 0) {b+=100;} polygon pp = p.rotate (theta * t); return pp.translate (a, b); } bool ast::inside(float x, float y, float t) { float a, b, c, d, Xa = 0, Ya = 0, Xb = 1, Yb = 2; int j, ss = 0, size; list pp; polygon jj; point pa, pb; jj = cp (t); pp = jj.vertices (); size = pp.size (); if (size < 1) { return -1; } pa = pp.tail (); for (j = 1; j <= size; j++) { pb = pa; pa = pp.pop (); Xa = pa.xcoord (); Xb = pb.xcoord (); Ya = pa.ycoord (); Yb = pb.ycoord (); a = Ya - Yb; b = Xa - Xb; c = -Ya * b + Xa * a; d = -y * b + x * a - c; if (d > 0) { ss=1; } //passed } if (ss == 0) { return 1; } return 0; } istream& operator >> (istream& in, ast& a) { in >> a.p; return in; } ostream& operator << (ostream& out, const ast & ) { return out; } #endif