Given four points in the three-dimensional space (the positions of the points and the points are not the same), determine whether the four points are in the same plane (the collinearity of the four points is also considered to be coplanar). If coplanar, output "Yes", otherwise output "No".
Input
Line 1: a number T, representing the number of tests entered (1 <= T <= 1000)
Line 2 - 4T + 1: 4 lines per line represent a set of data, 3 numbers per line, x, y, z , represents the position coordinates of the point (-1000 <= x, y, z <= 1000).
Output
Output a total of T lines, if it is coplanar, output "Yes", otherwise output "No".
Input example
1
1 2 0
2 3 0
4 0 0
0 0 0
Output example
Yes
About Computational Geometry: I am directly learning the template of a super inspirational senior from CSDN. I also hope that this senior will go well for the postgraduate entrance examination today!
Put her address directly:
https://blog.csdn.net/f_zyj/article/details/52060576
Principle: Mixed product of 3 vectors in space if! =0, it means that a parallelepiped can be formed, that is, the 4 points are not coplanar. If ==0, it means that the 4 points are coplanar, which means that the volume of the parallelepiped is 0.
AC code:
#include<bits/stdc++.h>
using namespace std;
struct point
{
double x, y, z;
point operator - (point &o)
{
point ans;
ans.x = this->x - o.x;
ans.y = this->y - o.y;
ans.z = this->z - o.z;
return ans;
}
};
double dot_product(const point &a, const point &b)
{
return a.x * b.x + a.y * b.y + a.z * b.z;
}
point cross_product(const point &a, const point &b)
{
point ans;
ans.x = a.y * b.z - a.z * b.y;
ans.y = a.z * b.x - a.x * b.z;
ans.z = a.x * b.y - a.y * b.x;
return ans;
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
ios_base::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
point p[4];
int t;
cin>>t;
while(t--)
{
for (int i = 0; i < 4; ++i)
{
cin>>p[i].x>>p[i].y>>p[i].z;
}
puts(dot_product(p[3] - p[0], cross_product(p[2] - p[0], p[1] - p[0])) == 0.0 ? "Yes\n" : "No\n");
}
return 0;
}