結果

問題 No.622 点と三角柱の内外判定
ユーザー lam6er
提出日時 2025-03-20 21:11:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 37 ms / 1,500 ms
コード長 1,730 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,444 KB
実行使用メモリ 53,988 KB
最終ジャッジ日時 2025-03-20 21:11:20
合計ジャッジ時間 2,224 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

ax, ay, az = map(int, input().split())
bx, by, bz = map(int, input().split())
cx, cy, cz = map(int, input().split())
dx, dy, dz = map(int, input().split())

# Calculate vectors AB and AC
ab = (bx - ax, by - ay, bz - az)
ac = (cx - ax, cy - ay, cz - az)

# Compute the normal vector (cross product AB x AC)
n = (
    ab[1] * ac[2] - ab[2] * ac[1],
    ab[2] * ac[0] - ab[0] * ac[2],
    ab[0] * ac[1] - ab[1] * ac[0]
)

# Compute the projection of D onto the plane ABC
denominator = n[0]**2 + n[1]**2 + n[2]**2
if denominator == 0:
    print("NO")
    exit()

n_dot = n[0] * (ax - dx) + n[1] * (ay - dy) + n[2] * (az - dz)
t = n_dot / denominator

px = dx + t * n[0]
py = dy + t * n[1]
pz = dz + t * n[2]

# Calculate vectors AP, AB, AC
ap = (px - ax, py - ay, pz - az)
ab = (bx - ax, by - ay, bz - az)
ac_vec = (cx - ax, cy - ay, cz - az)

# Determine the best pair of components to compute barycentric coordinates
det_xy = ab[0] * ac_vec[1] - ab[1] * ac_vec[0]
det_yz = ab[1] * ac_vec[2] - ab[2] * ac_vec[1]
det_zx = ab[2] * ac_vec[0] - ab[0] * ac_vec[2]

max_det = max(abs(det_xy), abs(det_yz), abs(det_zx))

if max_det == 0:
    print("NO")
    exit()

if max_det == abs(det_xy):
    a = ab[0]
    b = ac_vec[0]
    c = ap[0]
    d = ab[1]
    e = ac_vec[1]
    f = ap[1]
    det = det_xy
elif max_det == abs(det_yz):
    a = ab[1]
    b = ac_vec[1]
    c = ap[1]
    d = ab[2]
    e = ac_vec[2]
    f = ap[2]
    det = det_yz
else:
    a = ab[2]
    b = ac_vec[2]
    c = ap[2]
    d = ab[0]
    e = ac_vec[0]
    f = ap[0]
    det = det_zx

s = (e * c - b * f) / det
t_val = (a * f - d * c) / det

epsilon = 1e-10
if s >= -epsilon and t_val >= -epsilon and (s + t_val) <= 1.0 + epsilon:
    print("YES")
else:
    print("NO")
0