結果
問題 | No.622 点と三角柱の内外判定 |
ユーザー |
![]() |
提出日時 | 2017-12-22 12:49:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,500 ms |
コード長 | 2,378 bytes |
コンパイル時間 | 1,688 ms |
コンパイル使用メモリ | 172,108 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-17 23:09:01 |
合計ジャッジ時間 | 2,698 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
#include<bits/stdc++.h>using namespace std;class Vec {public:double x, y, z;Vec() {x = y = z = 0;}Vec(double x, double y, double z) : x(x), y(y), z(z) {}void rotate(double theta, double phi, double psi) {const double cosT = cos(theta), sinT = sin(theta), cosH = cos(phi), sinH = sin(phi), cosS = cos(psi), sinS = sin(psi);double tx = x, ty = y, tz = z;x = (cosT*cosS - sinT*cosH*sinS) * tx + (-cosT*sinS - sinT*cosH*cosS) * ty + ( sinT*sinH) * tz;y = (sinT*cosS + cosT*cosH*sinS) * tx + (-sinT*sinS + cosT*cosH*cosS) * ty + (-cosT*sinH) * tz;z = (sinH*sinS ) * tx + ( sinH*cosS ) * ty + ( cosH ) * tz;}double norm() const {return x * x + y * y + z * z;}Vec operator-(const Vec& v) const {return Vec(x - v.x, y - v.y, z - v.z);}Vec operator+(const Vec& v) const {return Vec(x + v.x, y + v.y, z + v.z);}};double dot(const Vec& a, const Vec& b) {return a.x * b.x + a.y * b.y + a.z * b.z;}Vec cross(const Vec& a, const Vec& b) {return Vec(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);}double getAngle(const Vec& a, const Vec& b) {if (a.norm() * b.norm() < 1e-9) return 0;return acos(dot(a, b) / sqrt(a.norm() * b.norm()));}void rotate(vector<Vec>& vec, double theta, double phi, double psi) {for (auto& v : vec)v.rotate(theta, phi, psi);}void normalize(vector<Vec>& v) {Vec v1 = v[0];Vec v2 = cross(v1, v[1]);double psi = getAngle(Vec(0, 1, 0), Vec(v2.x, v2.y, 0));double phi = getAngle(Vec(0, 0, 1), Vec(0, sqrt(v2.x * v2.x + v2.y * v2.y), v2.z));if (v2.x < 0) psi = -psi;v1.rotate(0, phi, psi);double theta = -getAngle(Vec(1, 0, 0), v1);if (v1.y < 0) theta = -theta;rotate(v, theta, phi, psi);}int main() {vector<Vec> a(4);for (int i = 0; i < 4; ++i) {cin >> a[i].x >> a[i].y >> a[i].z;}vector<Vec> v(3);for (int i = 0; i < 3; ++i) {v[i] = a[i + 1] - a[0];}normalize(v);Vec b = v[0], c = v[1], d = v[2];Vec _c = c - b, _d = d - b;_c.x = -_c.x;_d.x = -_d.x;if (d.y > 0 && c.x * d.y < d.x * c.y && _c.x * _d.y < _d.x * _c.y) {puts("YES");}elseputs("NO");return 0;}