Euclid(几何)

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2831

题意:已知A,B,C,D,E,F的坐标,求G,H的坐标,并且已知三角形DEF的面积等于平行四边形的面积,点H在AC上。

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <math.h>
 4 #include <iostream>
 5 #include <string.h>
 6 using namespace std;
 7 struct Point
 8 {
 9     double x,y;
10     Point(double x=0,double y=0):x(x),y(y) {}
11 };
12 typedef Point Vector;
13 
14 Vector operator -(Point a,Point b)
15 {
16     return Vector(a.x-b.x,a.y-b.y);
17 }
18 double Cross(Vector a,Vector b)
19 {
20     return (a.x*b.y-a.y*b.x);
21 }
22 int main()
23 {
24     double xa,ya,xb,yb,xc,yc,xd,yd,xe,ye,xf,yf;
25     while(cin>>xa>>ya>>xb>>yb>>xc>>yc>>xd>>yd>>xe>>ye>>xf>>yf)
26     {
27         if (xa==0&&ya==0&&xb==0&&yb==0&&xc==0&&yc==0&&xd==0&&yd==0&&xe==0&&ye==0&&xf==0&&yf==0)
28             break;
29         Point A(xa,ya),B(xb,yb),C(xc,yc),D(xd,yd),E(xe,ye),F(xf,yf);
30         Vector DE = E-D,DF= F-D,AB=B-A,AC=C-A;
31         double S1 = fabs(Cross(DE,DF))*1/2;
32         double S2 = fabs(Cross(AC,AB));
33         double k = S1/S2;
34         Vector AH(k*AC.x,k*AC.y);
35         Point H(AH.x+xa,AH.y+ya);
36         Point G(AB.x+H.x,AB.y+H.y);
37         printf("%.3f %.3f %.3f %.3f
",G.x,G.y,H.x,H.y);
38     }
39     return 0;
40 }
View Code
原文地址:https://www.cnblogs.com/lahblogs/p/3624059.html