51NOD1265(四点共面)

题目链接:点击打开链接


解题思路:

  判断四点共面,先求出三点构成的平面的法向量(叉积),如果第四个点和前三点任意一点构成的向量与平面法向量垂直(点积为0),则四点共面.

   回忆下叉积和点积.对于三位空间向量,叉积公式为

=(
),
=(
), a× b=(
-
) i+(
-
) j+(
-
) k,

写成行列式形式 .点积公式为

 , x1 * x2 + y1 * y2,自行扩展至三维.


完整代码:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <string>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <cstdlib>
#include <stack>
#include <time.h>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;
const int maxn = 100001;


class Point_3
{
public:
        double x , y , z;
        Point_3() {}
        Point_3(double xx , double yy , double zz) : x(xx)  , y(yy) , z(zz) {}
        void input()
        {
                scanf("%lf%lf%lf",&x,&y,&z);
        }
        friend Point_3 operator  - (const Point_3 &a , const Point_3 &b)
        {
                return Point_3(a.x - b.x , a.y - b.y , a.z - b.z);
        }
};

Point_3 det(const Point_3 &a , const Point_3 &b)
{
        return Point_3(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 dot(const Point_3 &a , const Point_3 &b)
{
        return a.x * b.x + a.y * b.y + a.z * b.z;
}

Point_3 pvec(Point_3 &s1 , Point_3 &s2 , Point_3 s3)
{
        return det((s1 - s2) , (s2 - s3));
}

bool zreo(double x)
{
        return fabs(x) < EPS;
}

int dots_onplane(Point_3  a , Point_3 b  , Point_3 c , Point_3 d )
{
        return zreo(dot(pvec(a , b , c ) , d - a));
}

int main()
{
#ifdef DoubleQ
    freopen("in.txt","r",stdin);
#endif
    int T;
    scanf("%d",&T);
    while(T--)
    {
            Point_3 a , b , c , d;
            a.input();
            b.input();
            c.input();
            d.input();
            if(dots_onplane(a , b , c , d))
                printf("Yes\n");
            else
                printf("No\n");
    }
    return 0;
}


/*************************************************
*
*   Copyright By DoubleQ
*   Written in 2015
*   Blog Address : zhanghe.ac.cn
*                  http://blog.csdn.net/u013447865
*   Email Address: acmer_doubleq@qq.com
*
*************************************************/



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值