标签:gif a+b include ide poi name scanf lin play
1 #include<iostream> 2 #include<cmath> 3 #include<cstdio> 4 using namespace std; 5 struct Point{ 6 double x,y; 7 Point operator - (const Point& b)const{ 8 return (Point){x-b.x,y-b.y}; 9 } 10 double operator ^ (const Point& b)const{ 11 return x*b.y - b.x*y; 12 } 13 Point operator * (const double b){ 14 return (Point){x*b,y*b}; 15 } 16 Point operator + (const Point& b)const{ 17 return (Point){x+b.x,y+b.y}; 18 } 19 }; 20 struct Line{ 21 Point s,t; 22 }; 23 //直线交 24 Point line_inter(Line l1,Line l2){ 25 double b = ((l1.t-l1.s)^(l2.s-l1.s))/((l2.t-l2.s)^(l1.t-l1.s)); 26 return l2.s + (l2.t - l2.s)*b; 27 } 28 double dis(Point a,Point b){ 29 return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)); 30 } 31 //外心 32 Point circumcenter(Point a, Point b, Point c){ 33 Line u, v; 34 u.s.x = (a.x + b.x) / 2; 35 u.s.y = (a.y + b.y) / 2; 36 u.t.x = u.s.x - a.y + b.y; 37 u.t.y = u.s.y + a.x - b.x; 38 v.s.x = (a.x + c.x) / 2; 39 v.s.y = (a.y + c.y) / 2; 40 v.t.x = v.s.x - a.y + c.y; 41 v.t.y = v.s.y + a.x - c.x; 42 return line_inter(u, v); 43 } 44 45 //内心 46 Point incenter(Point a,Point b,Point c){ //三角形内心 47 double A=dis(b,c); 48 double B=dis(a,c); 49 double C=dis(a,b); 50 double S=A+B+C; 51 double u=(A*a.x+B*b.x+C*c.x)/S; 52 double v=(A*a.y+B*b.y+C*c.y)/S; 53 return (Point){u,v}; 54 } 55 56 //垂心 57 Point perpencenter(Point a, Point b, Point c){ 58 Line u, v; 59 u.s = c; 60 u.t.x = u.s.x - a.y + b.y; 61 u.t.y = u.s.y + a.x - b.x; 62 v.s = b; 63 v.t.x = v.s.x - a.y + c.y; 64 v.t.y = v.s.y + a.x - c.x; 65 return line_inter(u, v); 66 } 67 68 //重心 69 //三条中线交点 70 //到三角形三顶点距离的平方和最小的点 71 //三角形内到三边距离之积最大的点 72 Point gravity(Point a, Point b, Point c){ 73 return (Point){(a.x+b.x+c.x)/3,(a.y+b.y+c.y)/3}; 74 } 75 76 //费马点 77 //到三角形三顶点距离之和最小的点 78 Point fermentpoint(Point a, Point b, Point c){ 79 Point u, v; 80 double step = fabs(a.x) + fabs(a.y) + fabs(b.x) + fabs(b.y) + fabs(c.x) + fabs(c.y); 81 int i, j, k; 82 u.x = (a.x + b.x + c.x) / 3; 83 u.y = (a.y + b.y + c.y) / 3; 84 while (step > 1e-10) 85 for (k = 0; k < 10; step /= 2, k++) 86 for (i = -1; i <= 1; i++) 87 for (j = -1; j <= 1; j++){ 88 v.x = u.x + step*i; 89 v.y = u.y + step*j; 90 if (dis(u, a) + dis(u, b) + dis(u, c) > dis(v, a) + dis(v, b) + dis(v, c)) 91 u = v; 92 } 93 return u; 94 } 95 int main(){ 96 int T; scanf("%d",&T); 97 Point a,b,c; 98 while(T--){ 99 cin>>a.x>>a.y; 100 cin>>b.x>>b.y; 101 cin>>c.x>>c.y; 102 Point ans = perpencenter(a,b,c); 103 printf("%.4f %.4f\n",ans.x,ans.y); 104 } 105 return 0; 106 }
标签:gif a+b include ide poi name scanf lin play
原文地址:https://www.cnblogs.com/xiaobuxie/p/11621844.html