计算几何
边的旋转、直线相交的应用
代码:
1 #include<cstdio> 2 #include<cmath> 3 using namespace std; 4 struct node 5 { 6 double x,y; 7 node(double x=0,double y=0):x(x),y(y){} 8 }a,b,c,d,e,f; 9 node operator-(node u,node v){return node(u.x-v.x,u.y-v.y);} 10 node operator+(node u,node v){return node(u.x+v.x,u.y+v.y);} 11 node operator*(node u,double v){return node(u.x*v,u.y*v);} 12 node operator/(node u,double v){return node(u.x/v,u.y/v);} 13 14 double cross(node u,node v) 15 { 16 return u.x*v.y-u.y*v.x; 17 } 18 19 node rotate(node a,double rad) 20 { 21 return node(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad)); 22 } 23 24 double dot(node a,node b) 25 { 26 return a.x*b.x+a.y*b.y; 27 } 28 29 double length(node a) 30 { 31 return sqrt(dot(a,a)); 32 } 33 34 double angle(node a,node b) 35 { 36 return acos(dot(a,b)/length(a)/length(b)); 37 } 38 39 node getnode(node p,node v,node q,node w) 40 { 41 node u=p-q; 42 double t=cross(w,u)/cross(v,w); 43 return p+v*t; 44 } 45 46 node get(node a,node b,node c) 47 { 48 node v1=c-b; 49 double a1=angle(a-b,v1); 50 v1=rotate(v1,a1/3); 51 node v2=b-c; 52 double a2=angle(a-c,v2); 53 v2=rotate(v2,-a2/3); 54 return getnode(b,v1,c,v2); 55 } 56 int main() 57 { 58 int n; 59 scanf("%d",&n); 60 while(n--) 61 { 62 scanf("%lf%lf",&a.x,&a.y); 63 scanf("%lf%lf",&b.x,&b.y); 64 scanf("%lf%lf",&c.x,&c.y); 65 d=get(a,b,c); 66 e=get(b,c,a); 67 f=get(c,a,b); 68 printf("%.6lf %.6lf ",d.x,d.y); 69 printf("%.6lf %.6lf ",e.x,e.y); 70 printf("%.6lf %.6lf ",f.x,f.y); 71 } 72 return 0; 73 }