Rope Crisis in Ropeland

// Rope Crisis in Ropeland.cpp : Defines the entry point for the console application. // #include "stdafx.h" using namespace std; const double PI=3.14159265; int _tmain(int argc, _TCHAR* argv[]) { double SolveToL(double x1,double y1,double x2,double y2,double r); double LongLine(double x1,double y1,double x2,double y2,double r,double ToLine); int testround=0; cin>>testround; while(testround>0) { double x1=0; double y1=0; double x2=0; double y2=0; double r=0; double OToL=0; double line=0; cin>>x1>>y1>>x2>>y2>>r; OToL=SolveToL(x1,y1,x2,y2,r); if(OToL<r*r) { line=LongLine(x1,y1,x2,y2,r,OToL); cout<<line<<"/n"; } else { double tmp=fabs(x1-x2)*fabs(x1-x2)+fabs(y1-y2)*fabs(y1-y2); line=sqrt(tmp); cout<<line<<"/n"; } --testround; } system("pause"); return 0; } double SolveToL(double x1,double y1,double x2,double y2,double r) { double a,b,Line; double x,y; a=0; b=0; Line=0; x=0; y=0; a=(y1-y2)/(x1-x2); b=y1-a*x1; x=-(a*b)/(a*a+1); y=a*x+b; Line=x*x+y*y; return Line; } double LongLine(double x1,double y1,double x2,double y2,double r,double ToLine) { double rope=0; double line1=sqrt(x1*x1+y1*y1-r*r); double line2=sqrt(x2*x2+y2*y2-r*r); double line3=0; double a1=0; double a2=0; double aD1=0; double aS1=0; double aD2=0; double aS2=0; double a=0; aD1=asin(r/sqrt(x1*x1+y1*y1)); aS1=asin(sqrt(ToLine)/sqrt(x1*x1+y1*y1)); a1=aD1-aS1; aD2=asin(r/sqrt(x2*x2+y2*y2)); aS1=asin(sqrt(ToLine)/sqrt(x2*x2+y2*y2)); a2=aD2-aS2; a=a1+a2; line3=2*PI*r*(a/(2*PI)); rope=line1+line2+line3; return rope; } 

你可能感兴趣的:(Rope Crisis in Ropeland)