啥也不说了,直接看图吧……
代码如下:
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
#define LL long long
struct point
{
LL x,y,z;
};
bool fun(point a,point b,point c,point d)
{
point p1, p2,p3;
p1.x = a.x-d.x;
p1.y = a.y-d.y;
p1.z = a.z-d.z; p2.x = a.x-c.x;
p2.y = a.y-c.y;
p2.z = a.z-c.z; p3.x = b.x-d.x;
p3.y = b.y-d.y;
p3.z = b.z-d.z; point w1,w2; w1.x = p1.y*p2.z-p2.y*p1.z;
w1.y = p1.z*p2.x-p2.z*p1.x;
w1.z = p1.x*p2.y-p2.x*p1.y; w2.x = p1.y*p3.z-p3.y*p1.z;
w2.y = p1.z*p3.x-p3.z*p1.x;
w2.z = p1.x*p3.y-p3.x*p1.y;
if(w1.x*w2.y==w2.x*w1.y && w1.z*w2.y==w2.z*w1.y)
return true;
return false;
}
LL dis(point a,point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z);
}
bool Dis(point a,point b,point c)
{
if(dis(b,c)>=dis(a,b)+dis(a,c))
return true;
return false;
}
bool T(point a,point b,point c,point d)
{
point p1, p2;
p1.x = a.x-b.x;
p1.y=a.y-b.y;
p1.z=a.z-b.z;
p2.x=c.x-d.x;
p2.y=c.y-d.y;
p2.z=c.z-d.z;
if(p1.x*p2.x+p1.y*p2.y+p1.z*p2.z == ){
return true;
}
else return false;
}
int main()
{
// freopen("J.in.cpp","r",stdin);
point a, b, c, d;
scanf("%I64d%I64d%I64d",&a.x,&a.y,&a.z);
scanf("%I64d%I64d%I64d",&b.x,&b.y,&b.z);
scanf("%I64d%I64d%I64d",&c.x,&c.y,&c.z);
scanf("%I64d%I64d%I64d",&d.x,&d.y,&d.z);
if(T(a,b,c,d) && fun(a,b,c,d) && Dis(b,a,d) && Dis(c,a,d))
{
printf("Valid\n");
}
else printf("Invalid\n");
return ;
}