LightOj1388 - Trapezium Drawing(求梯形点的坐标)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1388
题意:已知梯形的点A B的坐标,以及b c d的长度,求C D两点的坐标;默认AB是梯形平行边的较长边;
注意D点可能在A点的左边,AB可能不是水平的,剩下的求根据A点求D点,在根据D点求C点;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<set> using namespace std; #define met(a, b) memset(a, b, sizeof(a)) #define maxn 10005 #define maxm 20005 #define INF 0x3f3f3f3f typedef long long LL; int main() { int T, tcase = 1; scanf("%d", &T); while(T --) { double b, c, d, ax, ay, bx, by; scanf("%lf %lf %lf %lf %lf %lf %lf", &ax, &ay, &bx, &by, &b, &c, &d); double a = sqrt((ax-bx)*(ax-bx) + (ay-by)*(ay-by));///直线AB的距离; double sina = (by-ay) / a; double cosa = (bx-ax) / a; ///AB与水平线的sin和cos值; double p = (b+d+a-c)/2; double s = sqrt(p*(p-b)*(p-d)*(p-(a-c))); double h = s*2/(a-c);///D到AB的距离; int flag = 0; if(b*b > d*d + (a-c)*(a-c)) flag = 1;///角DAB为钝角; double t = sqrt(fabs(d*d - h*h)); if(flag) t = -t; double dx = ax + (t*cosa - h*sina); double dy = ay + (h*cosa + t*sina); double cx = dx + c*cosa; double cy = dy + c*sina; printf("Case %d:\n%.8lf %.8lf %.8lf %.8lf\n", tcase++, cx, cy, dx, dy); } return 0; }