您的位置:首页 > 其它

51NOD1265(四点共面)

2015-10-24 11:11 281 查看
题目链接:点击打开链接

解题思路:

  判断四点共面,先求出三点构成的平面的法向量(叉积),如果第四个点和前三点任意一点构成的向量与平面法向量垂直(点积为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
*
*************************************************/

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  计算几何