結果

問題 No.622 点と三角柱の内外判定
ユーザー wajima_wataruwajima_wataru
提出日時 2017-12-29 18:27:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 18 ms / 1,500 ms
コード長 1,558 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 11,064 KB
実行使用メモリ 8,924 KB
最終ジャッジ日時 2023-08-23 09:01:54
合計ジャッジ時間 2,211 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,852 KB
testcase_01 AC 17 ms
8,800 KB
testcase_02 AC 18 ms
8,724 KB
testcase_03 AC 17 ms
8,720 KB
testcase_04 AC 18 ms
8,720 KB
testcase_05 AC 18 ms
8,876 KB
testcase_06 AC 18 ms
8,856 KB
testcase_07 AC 17 ms
8,920 KB
testcase_08 AC 17 ms
8,924 KB
testcase_09 AC 17 ms
8,304 KB
testcase_10 AC 17 ms
8,828 KB
testcase_11 AC 17 ms
8,852 KB
testcase_12 AC 17 ms
8,684 KB
testcase_13 AC 17 ms
8,744 KB
testcase_14 AC 18 ms
8,740 KB
testcase_15 AC 17 ms
8,740 KB
testcase_16 AC 17 ms
8,536 KB
testcase_17 AC 17 ms
8,864 KB
testcase_18 AC 18 ms
8,716 KB
testcase_19 AC 17 ms
8,716 KB
testcase_20 AC 18 ms
8,724 KB
testcase_21 AC 18 ms
8,912 KB
testcase_22 AC 17 ms
8,724 KB
testcase_23 AC 18 ms
8,772 KB
testcase_24 AC 17 ms
8,844 KB
testcase_25 AC 17 ms
8,688 KB
testcase_26 AC 17 ms
8,724 KB
testcase_27 AC 16 ms
8,684 KB
testcase_28 AC 18 ms
8,864 KB
testcase_29 AC 17 ms
8,684 KB
testcase_30 AC 17 ms
8,728 KB
testcase_31 AC 17 ms
8,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sin, cos, atan2
from operator import *
pos = []
for _ in range(4):
	pos.append(list(map(float, input().split())))


def rotate_x(p, theta):
	q = []
	q.append(p[0])
	q.append(p[1] * cos(theta) - p[2] * sin(theta))
	q.append(p[1] * sin(theta) + p[2] * cos(theta))
	return q

def rotate_y(p, theta):
	q = []
	q.append(p[2] * sin(theta) + p[0] * cos(theta))
	q.append(p[1])
	q.append(p[2] * cos(theta) - p[0] * sin(theta))
	return q

def rotate_z(p, theta):
	q = []
	q.append(p[0] * cos(theta) - p[1] * sin(theta))
	q.append(p[0] * sin(theta) + p[1] * cos(theta))
	q.append(p[2])
	return q

def translate(p, q):
	for i in range(3):
		p[i] += q[i]
	return p


d = list(map(neg, pos[0]))
for i in range(4):
	pos[i] = translate(pos[i], d)

th1 = atan2(pos[1][2], pos[1][0])
for i in range(4):
	pos[i] = rotate_y(pos[i], th1)

th2 = atan2(-pos[1][1], pos[1][0])
for i in range(4):
	pos[i] = rotate_z(pos[i], th2)

th3 = atan2(-pos[2][2], pos[2][1])
for i in range(4):
	pos[i] = rotate_x(pos[i], th3)

AD = [pos[3][0] - pos[0][0], pos[3][1] - pos[0][1]]
BD = [pos[3][0] - pos[1][0], pos[3][1] - pos[1][1]]
CD = [pos[3][0] - pos[2][0], pos[3][1] - pos[2][1]]
AB = [pos[1][0] - pos[0][0], pos[1][1] - pos[0][1]]
BC = [pos[2][0] - pos[1][0], pos[2][1] - pos[1][1]]
CA = [pos[0][0] - pos[2][0], pos[0][1] - pos[2][1]]


def cross(a, b):
	return a[0] * b[1] - b[0] * a[1]


if cross(AB, BD) > 0 and cross(BC, CD) > 0 and cross(CA, AD) > 0:
	print('YES')
elif cross(AB, BD) < 0 and cross(BC, CD) < 0 and cross(CA, AD) < 0:
	print('YES')
else:
	print('NO')
0