已知ABDE, BCHJ 和 ACFG 是正方形,L, M, N 分别是中点,求证 o 是三角形ABC的垂心。
队友lwc的证明就是证 三角形ABC 和 三角形BJQ 全等, 其中BM == MQ;
直接暴搞的代码:
1 #include<iostream>
2 #include<cmath>
3 #include<stdio.h>
4 using namespace std;
5 const double PI = 3.1415926535897932384626433832795;
6 const double eps = 1e-8;
7 int dcmp(double x){return x < -eps ? -1 : x > eps ;}
8
9 double fix(double x){
10 if(dcmp(x)==0)return 0;
11 return x;
12 }
13
14 struct Point {
15 double x, y;
16 Point() {}
17 Point(double x0, double y0): x(x0), y(y0) {}
18 };
19
20 double operator*(Point p1, Point p2) // 计算叉乘 p1 × p2
21 {
22 return (p1.x * p2.y - p2.x * p1.y);
23 }
24 Point operator-(Point p1, Point p2)
25 {
26 return Point(p1.x - p2.x, p1.y - p2.y);
27 }
28 Point operator+(Point p1, Point p2)
29 {
30 return Point(p1.x + p2.x, p1.y + p2.y);
31 }
32 Point Rotate(Point p, double angle)
33 {
34 Point result;
35 result.x = p.x * cos(angle) - p.y * sin(angle);
36 result.y = p.x * sin(angle) + p.y * cos(angle);
37 return result;
38 }
39 double Area(Point A, Point B, Point C) //三角形面积
40 {
41 return ((B-A)*(C-A) / 2.0);
42 }
43
44 Point intersection(Point u1,Point u2,Point v1,Point v2){
45 Point ret=u1;
46 double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
47 /((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
48 ret.x+=(u2.x-u1.x)*t;
49 ret.y+=(u2.y-u1.y)*t;
50 return ret;
51 }
52
53 int main()
54 {
55 int T, cas;
56 Point a, b, c;
57 scanf("%d",&T);
58 for(cas = 0; cas < T; cas++)
59 {
60 scanf("%lf%lf",&a.x, &a.y);
61 scanf("%lf%lf",&b.x, &b.y);
62 scanf("%lf%lf",&c.x, &c.y);
63 if(Area(a,b,c) < 0)swap(b,c);
64 Point p, q, r, s, ans;
65 p = Rotate(b - a,-PI/2) + a;
66 q = Rotate(c - a, PI/2) + a;
67 r = (p + q);
68 r.x/=2; r.y/=2;
69
70 p = Rotate(c - b,-PI/2) + b;
71 q = Rotate(a - b, PI/2) + b;
72 s = (p + q);
73 s.x/=2; s.y/=2;
74 ans = intersection(a, r, b, s);
75 printf("%.4lf %.4lf\n",fix(ans.x), fix(ans.y));
76 }
77 }
posted on 2009-07-11 20:58
wangzhihao 阅读(962)
评论(0) 编辑 收藏 引用 所属分类:
geometry