#include #include #include #include using namespace std; struct vec { // 3次元ベクトル double x; double y; double z; vec (double x = 0.0, double y = 0.0, double z = 0.0) { vec::x = x; vec::y = y; vec::z = z; } vec operator +(vec const & r ) { return vec{ x + r.x, y + r.y, z + r.z }; } vec operator -(vec const & r ) { return vec{ x - r.x, y - r.y, z - r.z }; } double dot (vec const &r) { // (l, r) return x * r.x + y * r.y + z * r.z; } vec cross (vec const &r) { // l x r return vec{ y * r.z - z * r.y, z * r.x - x * r.z, x * r.y - y * r.x }; } double pow2_magnitude() { return pow(x, 2) + pow(y, 2) + pow(z, 2); } }; vec operator*(double k, vec r) { // k * r; return vec{ k * r.x, k * r.y, k * r.z }; } vec normal_vec(vec triangle[]) { vec ab = triangle[1] - triangle[0]; vec ac = triangle[2] - triangle[0]; return ab.cross(ac); } bool is_inside_triangle(vec p, vec triangle[]) { vec ab = triangle[1] - triangle[0]; vec bp = p - triangle[1]; vec bc = triangle[2] - triangle[1]; vec cp = p - triangle[2]; vec ca = triangle[0] - triangle[2]; vec ap = p - triangle[0]; vec ab_x_bp = ab.cross(bp); vec bc_x_cp = bc.cross(cp); vec ca_x_ap = ca.cross(ap); if (ab_x_bp.dot(bc_x_cp) > 0 && bc_x_cp.dot(ca_x_ap) > 0) { return true; } else { return false; } } bool is_inside_prism(vec p, vec triangle[]) { vec n = normal_vec(triangle); double d = -n.dot(triangle[0]); vec h = p - (n.dot(p) + d) / n.dot(n) * n; // pから三角形に下ろした垂線の足 // cout << h.x << " " << h.y << " " << h.z << endl; return is_inside_triangle(h, triangle); } int main(int argc, char *argv[]) { vec a, b, c, d; cin >> a.x >> a.y >> a.z; cin >> b.x >> b.y >> b.z; cin >> c.x >> c.y >> c.z; cin >> d.x >> d.y >> d.z; vec triangle [3] = {a, b, c}; cout << (is_inside_prism(d, triangle) ? "YES" : "NO") << endl; return 0; }