結果

問題 No.622 点と三角柱の内外判定
ユーザー りあんりあん
提出日時 2017-12-22 12:49:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 2,378 bytes
コンパイル時間 1,573 ms
コンパイル使用メモリ 168,848 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-22 21:15:56
合計ジャッジ時間 2,874 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,504 KB
testcase_31 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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");
    }
    else
        puts("NO");

    return 0;
}
0