题意:给两个点的x,y坐标以及当前点与他们的角度,求当前点的位置。
题解:每一个点的坐标与角度可以构成一条直线,然后求两直线交点。
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include<cstdlib> 2 #include<cmath> 3 #include<cstdio> 4 #include<algorithm> 5 #define max(a,b) (((a)>(b))?(a):(b)) 6 #define min(a,b) (((a)>(b))?(b):(a)) 7 #define sign(x) ((x)>eps?1:((x)<-eps?(-1):(0))) //符号函数 8 using namespace std; 9 const int MAXN=1000; 10 const double eps=1e-8,inf=1e50,PI=acos(-1.0); 11 struct point 12 { 13 double x,y; 14 point(){} 15 point(double _x,double _y){x=_x;y=_y;} 16 }; 17 struct line 18 { 19 point a,b; 20 line(){} 21 line(point _a,point _b){a=_a;b=_b;} 22 }; 23 inline double xmult(point o,point a,point b) 24 { 25 return (a.x-o.x)*(b.y-o.y)-(b.x-o.x)*(a.y-o.y); 26 } 27 inline double xmult(double x1,double y1,double x2,double y2) 28 { 29 return x1*y2-x2*y1; 30 } 31 inline double dmult(point o,point a,point b) 32 { 33 return (a.x-o.x)*(b.x-o.x)+(a.y-o.y)*(b.y-o.y); 34 } 35 //求直线交点,必须存在交点,或者预判断 36 point line_intersection(line u,line v) 37 { 38 double a1=u.b.y-u.a.y,b1=u.a.x-u.b.x; 39 double c1=u.b.y*(-b1)-u.b.x*a1; 40 double a2=v.b.y-v.a.y,b2=v.a.x-v.b.x; 41 double c2=v.b.y*(-b2)-v.b.x*a2; 42 double D=xmult(a1,b1,a2,b2); 43 return point(xmult(b1,c1,b2,c2)/D,xmult(c1,a1,c2,a2)/D); 44 } 45 void counter (double &x,double &y,double th) 46 { 47 //绕原点逆时针旋转th弧度,顺时针则传入-th 48 double tx=x,ty=y; 49 x=tx*cos(th)-ty*sin(th); 50 y=tx*sin(th)+ty*cos(th); 51 return; 52 } 53 int main() 54 { 55 int T; 56 for(scanf("%d",&T);T;T--) 57 { 58 point a,b,c; 59 line u,v; 60 double d1,d2,x,y; 61 scanf("%lf%lf%lf",&a.x,&a.y,&d1); 62 scanf("%lf%lf%lf",&b.x,&b.y,&d2); 63 x=0,y=-1; 64 counter(x,y,-d1/180.0*PI); 65 u=line(a,point(a.x+x,a.y+y)); 66 x=0,y=-1; 67 counter(x,y,-d2/180.0*PI); 68 v=line(b,point(b.x+x,b.y+y)); 69 c=line_intersection(u,v); 70 printf("%.4lf %.4lf\n",c.x,c.y); 71 } 72 return 0; 73 }