Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<string>
- #include<iostream>
- #include<iomanip>
- #include<cmath>
- #include<cstdlib>
- using namespace std;
- float xo, yo, r, xa, ya, xb, yb, a, b, c, d, e, delta, n, xs, ys, xk, yk;
- float xp1, xp2, yp1, yp2, x, y;
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin>>n;
- for(int i=0; i<n; i++)
- {
- cin>>xo>>yo>>r>>xa>>ya>>xb>>yb;
- if(xb-xa!=0)
- a=(yb-ya)/(xb-xa);
- else
- a=0;
- b=a*(-1*xa)+ya;
- c=1+a*a;
- d=2*(-1*xo)+(b-yo)*2*a;
- e=xo*xo+(b-yo)*(b-yo)-1*(r*r);
- delta=d*d-4*c*e;
- if(xa==xb)
- {
- xp1=xa;
- xp2=xa;
- yp1=sqrt(r*r-(xa-xo)*(xa-xo))+yo;
- yp2=-1*(sqrt(r*r-(xa-xo)*(xa-xo))+yo);
- }
- else
- {
- xp1=(-d+sqrt(delta))/(2*c);
- xp2=(-d-sqrt(delta))/(2*c);
- yp1=a*xp1+b;
- yp2=a*xp2+b;
- }
- if(ya>yb)
- {
- xs=xa;
- ys=ya;
- xk=xb;
- yk=yb;
- }
- else
- {
- if(ya<yb)
- {xs=xb;
- ys=yb;
- xk=xa;
- yk=ya;}
- if(ya==yb)
- {
- xs=max(xa,xb);
- xk=min(xa,xb);
- ys=ya;
- yk=ya;
- }
- }
- if(a>=0)
- {
- if(xp1>=xk&&xp1<=xs)
- {
- cout<<fixed<<setprecision(2)<<xp1<<" "<<yp1<<endl;
- continue;
- }
- if(xp2>=xk&&xp2<=xs)
- {
- cout<<fixed<<setprecision(2)<<xp2<<" "<<yp2<<endl;
- continue;
- }
- }
- if(a<0)
- {
- if(xp1<=xk&&xp1>=xs)
- {
- cout<<fixed<<setprecision(2)<<xp1<<" "<<yp1<<endl;
- continue;
- }
- if(xp2<=xk&&xp2>=xs)
- {
- cout<<fixed<<setprecision(2)<<xp2<<" "<<yp2<<endl;
- continue;
- }
- }
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement