题意:给2个坐标a1,a2,求以这两个点的连线作为对角线的正方形的另外两个点。
解题思路:另外两个点的坐标可以看作a1,a2绕中点旋转90度。中点加减上一半的直线a1a2旋转90度后的坐标得到的两个点就是要求的两个点。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
double x1,x2,y1,y2,a,b;
int main () {
freopen("xx.in","r",stdin);
while (scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF) {
if (x1 == x2 && y1 == y2) {
printf("Impossible\n");
continue;
}
a= (x1 + x2)/ 2.000000000000;
b= (y1 + y2)/ 2.000000000000;
double i= x2 - x1, j= y2 - y1;
i/=2.000000000;
j/=2.000000000;
printf("%.10lf %.10lf %.10lf %.10lf\n",a-j,b+i,a+j,b-i);
}
}