首页 > 代码库 > 51nod_1265:四点共面(计算几何)

51nod_1265:四点共面(计算几何)

题目链接

设四点为a_0~3,若共面则 (a1a0*a2a0)·a3a0=0

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;

const double eps=1e-8;

struct point
{
    double x,y,z;
    point operator -(const point& rhs)
    {
        point ret;
        ret.x=x-rhs.x;ret.y=y-rhs.y;ret.z=z-rhs.z;
        return ret;
    }
    point operator ^(const point& rhs)
    {
        point ret;
        ret.x=y*rhs.z-z*rhs.y;
        ret.y=z*rhs.x-x*rhs.z;
        ret.z=x*rhs.y-y*rhs.x;
        return ret;
    }
    double operator *(const point& rhs)
    {
        return x*rhs.x+y*rhs.y+z*rhs.z;
    }
}a[4];

bool ok()
{
    return ((a[1]-a[0])^(a[2]-a[0]))*(a[3]-a[0]);
}

int main()
{
    int T;cin>>T;
    while(T--)
    {
        for(int i=0;i<4;i++)
            cin>>a[i].x>>a[i].y>>a[i].z;
        if(!ok()) puts("Yes");
        else puts("NO");
    }
}

 

51nod_1265:四点共面(计算几何)