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
*
*************************************************/
解题思路:
判断四点共面,先求出三点构成的平面的法向量(叉积),如果第四个点和前三点任意一点构成的向量与平面法向量垂直(点积为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
*
*************************************************/
相关文章推荐
- 初学算法 - 求凸包的Garham's Scan算法的C++实现
- 【Google Code Jam 2009 round2 problem D】Watering Plants (两圆交点求法详解)
- 计算几何模板
- 计算几何小模板
- BZOJ2829信用卡凸包
- HDU 4922 Hello, Your Package! (计算几何+DP)(WA)
- poj 1514&zoj 1185 Metal Cutting(半平面交)
- UVA 10969 Sweet Dream(圆的相交)
- uva 11177 Fighting Against a Polygonal Monster(凸包与圆的面积交)
- POJ1279 && LA2512 Art Gallery(求多边形的核)
- poj 2540 && uva 10084 Hotter Colder(半平面交)
- 【计算几何】POJ 2318 & POJ 2398
- 【计算几何】POJ 2653
- 【计算几何】POJ 1113
- HDU 5128 The E-pang Palace
- POJ 2318 TOYS(叉积+二分or暴力)
- POJ 2398 Toy Storage(叉积+二分)
- POJ 1228 Grandpa's Estate 计算凸包+判断点在线段上
- POJ 1873 The Fortified Forest 计算凸包
- POJ 2007 Scrambled Polygon 极角排序