import std; void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; Vec3 readVec3() { double x, y, z; scan(x, y, z); return Vec3(x, y, z); } // 点 H が三角形 ABC の内側にあるか bool isPointInTriangle(Vec3 H, Vec3 A, Vec3 B, Vec3 C) { auto AB = B - A; auto BC = C - B; auto CA = A - C; auto AH = H - A; auto BH = H - B; auto CH = H - C; auto a = AB.cross(AH); auto b = BC.cross(BH); auto c = CA.cross(CH); if (sgn(a.dot(b)) == sgn(b.dot(c)) && sgn(b.dot(c)) == sgn(c.dot(a))) { return true; } return false; } void main() { auto A = readVec3(); auto B = readVec3(); auto C = readVec3(); auto D = readVec3(); auto AB = B - A; auto AC = C - A; auto n = AB.cross(AC).normalized(); auto AD = D - A; // AD ベクトルの n ベクトルへの射影ベクトル auto m = AD.dot(n) * n; // 点 D から三角形 ABC へ下ろした垂線の足を H とする auto AH = AD - m; // 点 H の座標 auto H = A + AH; if (isPointInTriangle(H, A, B, C)) { writeln("YES"); } else writeln("NO"); } struct Vec3 { immutable double x; immutable double y; immutable double z; this(double x, double y, double z) { this.x = x; this.y = y; this.z = z; } double dot(Vec3 o) { return this.x * o.x + this.y * o.y + this.z * o.z; } Vec3 cross(Vec3 o) { auto x = this.y * o.z - o.y * this.z; auto y = this.z * o.x - o.z * this.x; auto z = this.x * o.y - o.x * this.y; return Vec3(x, y, z); } double mag() { return sqrt(magSq()); } double magSq() { return this.x * this.x + this.y * this.y + this.z * this.z; } Vec3 normalized() { auto m = mag(); return Vec3(this.x / m, this.y / m, this.z / m); } Vec3 opUnary(string op)() if (op == "-") { return Vec3(-this.x, -this.y, -this.z); } Vec3 opBinary(string op)(Vec3 o) if (op == "+") { return Vec3(this.x + o.x, this.y + o.y, this.z + o.z); } Vec3 opBinary(string op)(Vec3 o) if (op == "-") { return Vec3(this.x - o.x, this.y - o.y, this.z - o.z); } Vec3 opBinary(string op)(double d) if (op == "*") { return Vec3(this.x * d, this.y * d, this.z * d); } Vec3 opBinaryRight(string op)(double d) if (op == "*") { return Vec3(this.x * d, this.y * d, this.z * d); } }