Uva--10250 (简单几何)
2014-06-12 21:31:35
题意&思路:哎,yy多了浪费时间,静下心来细心推导5分钟便可出。简单题不多说。
#include <cstdio> #include <iostream> #include <cmath> using namespace std; int main(){ double x1,y1,x2,y2,x3,y3,C,xa,ya,xb,yb; while(cin >> x1 >> y1 >> x2 >> y2){ x3 = (x1 + x2) / 2; y3 = (y1 + y2) / 2; if(y1 == y2){ double d = fabs(x1 - x2); xa = xb = x3; ya = y1 + d / 2; yb = y1 - d / 2; } else if(x1 == x2){ double d = fabs(y1 - y2); ya = yb = y3; xa = x1 - d / 2; xb = x1 + d / 2; } else{ C = ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) / 4; xa = sqrt(C * (y2 - y1) * (y2 - y1) / ((y2 - y1) * (y2 - y1) + (x1 - x2) * (x1 - x2))) + x3; ya = (xa - x3) * (x1 - x2) / (y2 - y1) + y3; xb = 2 * x3 - xa; yb = 2 * y3 - ya; } printf("%.10lf %.10lf %.10lf %.10lf\n",xa,ya,xb,yb); } return 0; }