题目:给你平行四边形两条边的顶点,让你求第四个点。
分析:计算几何,简单题。为什么给出的是4个点呢,其实3个点就够了,一定有陷阱╮(╯▽╰)╭。
给出的点不一定是按顺序给的,所以计算前先调整顺序。然后利用向量计算即可。
注意:给出的第二个点和第三个点不一定是同一个点,别被输入误导。
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;
typedef struct pnode
{
double x,y;
pnode( double a, double b ){x = a;y = b;}
pnode(){}
}point;
int main()
{
point a,b,c,d;
while ( ~scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y) ) {
scanf("%lf%lf%lf%lf",&c.x,&c.y,&d.x,&d.y);
//调整,让b和c坐标相同
if ( a.x == c.x && a.y == c.y )
swap( a, b );
if ( a.x == d.x && a.y == d.y ) {
swap( a, b );swap( c, d );
}
if ( b.x == d.x && b.y == d.y )
swap( c, d );
point e = point( a.x+d.x-c.x, a.y+d.y-c.y );
printf("%.3lf %.3lf\n",e.x,e.y);
}
return 0;
}