Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include<string>
  2. #include<iostream>
  3. #include<iomanip>
  4. #include<cmath>
  5. #include<cstdlib>
  6.  
  7. using namespace std;
  8.  
  9. float xo, yo, r, xa, ya, xb, yb, a, b, c, d, e, delta, n, xs, ys, xk, yk;
  10. float xp1, xp2, yp1, yp2, x, y;
  11.  
  12. int main()
  13. {
  14.  
  15. ios_base::sync_with_stdio(0);
  16.  
  17. cin>>n;
  18.  
  19. for(int i=0; i<n; i++)
  20. {
  21. cin>>xo>>yo>>r>>xa>>ya>>xb>>yb;
  22.  
  23. if(xb-xa!=0)
  24. a=(yb-ya)/(xb-xa);
  25. else
  26. a=0;
  27.  
  28. b=a*(-1*xa)+ya;
  29.  
  30. c=1+a*a;
  31. d=2*(-1*xo)+(b-yo)*2*a;
  32. e=xo*xo+(b-yo)*(b-yo)-1*(r*r);
  33.  
  34. delta=d*d-4*c*e;
  35.  
  36. if(xa==xb)
  37. {
  38. xp1=xa;
  39. xp2=xa;
  40. yp1=sqrt(r*r-(xa-xo)*(xa-xo))+yo;
  41. yp2=-1*(sqrt(r*r-(xa-xo)*(xa-xo))+yo);
  42. }
  43. else
  44. {
  45. xp1=(-d+sqrt(delta))/(2*c);
  46. xp2=(-d-sqrt(delta))/(2*c);
  47. yp1=a*xp1+b;
  48. yp2=a*xp2+b;
  49. }
  50. if(ya>yb)
  51. {
  52. xs=xa;
  53. ys=ya;
  54. xk=xb;
  55. yk=yb;
  56. }
  57. else
  58. {
  59. if(ya<yb)
  60. {xs=xb;
  61. ys=yb;
  62. xk=xa;
  63. yk=ya;}
  64.  
  65. if(ya==yb)
  66. {
  67. xs=max(xa,xb);
  68. xk=min(xa,xb);
  69. ys=ya;
  70. yk=ya;
  71. }
  72. }
  73.  
  74.  
  75.  
  76. if(a>=0)
  77. {
  78. if(xp1>=xk&&xp1<=xs)
  79. {
  80. cout<<fixed<<setprecision(2)<<xp1<<" "<<yp1<<endl;
  81. continue;
  82. }
  83.  
  84. if(xp2>=xk&&xp2<=xs)
  85. {
  86. cout<<fixed<<setprecision(2)<<xp2<<" "<<yp2<<endl;
  87. continue;
  88. }
  89.  
  90. }
  91.  
  92. if(a<0)
  93. {
  94. if(xp1<=xk&&xp1>=xs)
  95. {
  96. cout<<fixed<<setprecision(2)<<xp1<<" "<<yp1<<endl;
  97. continue;
  98. }
  99.  
  100. if(xp2<=xk&&xp2>=xs)
  101. {
  102. cout<<fixed<<setprecision(2)<<xp2<<" "<<yp2<<endl;
  103. continue;
  104. }
  105. }
  106.  
  107.  
  108.  
  109. }
  110. system("PAUSE");
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement