/* -*- coding: utf-8 -*- * * 622.cc: No.622 点と三角柱の内外判定 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ /* typedef */ template struct Pt3d { T x, y, z; Pt3d() {} Pt3d(T _x, T _y, T _z) : x(_x), y(_y), z(_z) {} Pt3d(const Pt3d& pt) : x(pt.x), y(pt.y), z(pt.z) {} bool operator==(const Pt3d pt) const { return x == pt.x && y == pt.y && z == pt.z; } Pt3d operator+(const Pt3d pt) const { return Pt3d(x + pt.x, y + pt.y, z + pt.z); } Pt3d operator-() const { return Pt3d(-x, -y, -z); } Pt3d operator-(const Pt3d pt) const { return Pt3d(x - pt.x, y - pt.y, z - pt.z); } Pt3d operator*(T t) const { return Pt3d(x * t, y * t, z * t); } Pt3d operator/(T t) const { return Pt3d(x / t, y / t, z / t); } T dot(Pt3d v) const { return x * v.x + y * v.y + z * v.z; } Pt3d cross(Pt3d v) const { return Pt3d(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x); } Pt3d mid(const Pt3d pt) { return Pt3d((x + pt.x) / 2, (y + pt.y) / 2, (z + pt.z) / 2); } T d2() { return x * x + y * y + z * z; } double d() { return sqrt(d2()); } Pt3d rotx(double th) { double c = cos(th), s = sin(th); return Pt3d(x, c * y - s * z, s * y + c * z); } Pt3d roty(double th) { double c = cos(th), s = sin(th); return Pt3d(s * z + c * x, y, c * z - s * x); } Pt3d rotz(double th) { double c = cos(th), s = sin(th); return Pt3d(c * x - s * y, s * x + c * y, z); } Pt3d rotx90() { return Pt3d(x, -z, y); } Pt3d roty90() { return Pt3d(z, y, -x); } Pt3d rotz90() { return Pt3d(-y, x, z); } bool operator<(const Pt3d& pt) const { return (x < pt.x || (x == pt.x && (y < pt.y || (y == pt.y && z < pt.z)))); } void print(string format) { printf(("(" + format + ", " + format + ", " + format + ")\n").c_str(), x, y, z); } void print() { print("%.6lf"); } }; typedef Pt3d pt; /* subroutines */ /* global variables */ pt ps[4], nvs[3]; /* subroutines */ /* main */ /* p = t*nv+q (p-p0)*nv=(t*nv+q-p0)*nv=0 -> t*(nv*nv)=(p0-q)*nv -> t = (p0-q)*nv/(nv*nv) */ int main() { for (int i = 0; i < 4; i++) scanf("%lf%lf%lf", &ps[i].x, &ps[i].y, &ps[i].z); pt &q = ps[3]; pt nv((ps[1] - ps[0]).cross(ps[2] - ps[0])); double t = (ps[0] - q).dot(nv) / nv.d2(); pt p(nv * t + q); //p.print(); for (int i = 0; i < 3; i++) { pt v0(ps[(i + 1) % 3] - ps[i]), v1(p - ps[i]); nvs[i] = v0.cross(v1); //nvs[i].print(); } for (int i = 0; i < 3; i++) { double d = nvs[i].dot(nvs[(i + 1) % 3]); //printf("%lf\n", d); if (d <= 0.0) { puts("NO"); return 0; } } puts("YES"); return 0; }