A、Rescue The Princess

已知一个等边三角形的两个顶点A、B,求第三个顶点C,A、B、C成逆时针方向。

常规的解题思路就是用已知的两个点列出x,y方程,但这样求出方程的解的表达式比较复杂。更为简单的方法就是以A的坐标加A、C直线的角度求解,使用atan2函数求出A、B直线的角度再加上60就是A、C的角度,使用A、B求出等边三角形的边长。

 1 #include <cstdio>
 2 #include <cmath>
 3 #include <iostream>
 4 
 5 using namespace std;
 6 
 7 const double pi = acos(-1.0);
 8 double xx1,yy1,xx2,yy2,xx3,yy3,jiao,leng;
 9 
10 int main(int argc, char const *argv[])
11 {
12     freopen("SD_3230_Rescue_The_Princess.in","r",stdin);
13     int amount;
14     scanf("%d",&amount);
15     while(amount--){
16         scanf("%lf %lf %lf %lf",&xx1,&yy1,&xx2,&yy2);
17         jiao = atan2(yy2-yy1,xx2-xx1);
18         leng = sqrt(pow(xx1-xx2,2)+pow(yy1-yy2,2));
19         xx3 = xx1 + leng*cos(jiao+pi/3.0);
20         yy3 = yy1 + leng*sin(jiao+pi/3.0);
21         printf("(%.2lf,%.2lf)\n", xx3,yy3);
22     }
23     return 0;
24 }
View Code

相关文章:

  • 2021-09-23
  • 2021-09-13
  • 2022-12-23
  • 2021-08-09
  • 2021-09-10
猜你喜欢
  • 2021-10-10
  • 2021-04-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2021-06-14
  • 2021-05-04
相关资源
相似解决方案