Area of a Parallelogram(数学啊 )

题目链接:?problem=1305

A parallelogram is a quadrilateral with two pairs of parallel sides. See the picture below:

Fig: a parallelogram

Now you are given the co ordinates ofA, BandC, you have to find the coordinates ofDand the area of the parallelogram. The orientation ofABCDshould be same as in the picture.

Input

Input starts with an integerT (≤ 1000), denoting the number of test cases.

Each case starts with a line containing six integersAx, Ay, Bx, By, Cx, Cywhere(Ax, Ay)denotes the coordinate ofA,(Bx, By)denotes the coordinate ofBand(Cx, Cy)denotes the coordinate ofC. Value of any coordinate lies in the range[-1000, 1000]. And you can assume thatA, BandCwill not be collinear.

Output

For each case, print the case number and three integers where the first two should be the coordinate ofDand the third one should be the area of the parallelogram.

Sample InputOutput for Sample Input

3

0 0 10 0 10 10

0 0 10 0 10 -20

-12 -10 21 21 1 40

Case 1: 0 10 100

Case 2: 0 -20 200

Case 3: -32 9 1247

题意:

求平行四边形的D点和面积!

代码如下:

#include <cstdio>#include <cmath>#include <cstring>#include <iostream>#include <algorithm>using namespace std;double dis(int x1, int y1, int x2, int y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}int main(){int t;int cas = 0;scanf("%d",&t);while(t–){int ax,ay, bx, by, cx, cy;int dx, dy;double area;scanf("%d%d%d%d%d%d",&ax,&ay,&bx,&by,&cx,&cy);int xx = bx – ax;int yy = cy – by;dx = cx – xx;dy = ay + yy;double dis_AD = dis(ax,ay,dx,dy);double dis_DB = dis(dx,dy,bx,by);double dis_AB = dis(ax,ay,bx,by);double cosA;if(((dis_AD)*(dis_AD)+(dis_AB)*(dis_AB) == (dis_DB)*(dis_DB))){cosA = 0;}elsecosA = (dis_AD*dis_AD+dis_AB*dis_AB-dis_DB*dis_DB)/(2*dis_AD*dis_AB);double sinA = sqrt(1-cosA*cosA);area = dis_AD * dis_AB * sinA;printf("Case %d: %d %d %.0lf\n",++cas,dx,dy,area);}return 0;}/*30 0 10 0 10 100 0 10 0 10 -20-12 -10 21 21 1 40*/

,如你想要拥有完美无暇的友谊,可能一辈子找不到朋友

Area of a Parallelogram(数学啊 )

相关文章:

你感兴趣的文章:

标签云: