結果

問題 No.622 点と三角柱の内外判定
ユーザー norioc
提出日時 2019-10-30 01:33:11
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 2,591 bytes
コンパイル時間 2,551 ms
コンパイル使用メモリ 179,632 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 02:59:00
合計ジャッジ時間 2,322 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

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); }
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0