#include<iostream>
#include <iomanip>//输出精度的控制文件
#include<cmath>//abs()函数需要的文件
#include<math.h>
using namespace std;
int main()
{
int n;
cin>>n;
double a,b,a0,b0,r,x,y,w,t;
while(n--){
double distance,distan;
cin>>a>>b>>r>>x>>y>>w>>t;
a0 = a + cos(w*t)*r;//动点的横坐标
b0 = b + sin(w*t)*r;
if(a0==a)//如果直线斜率不存在(及支线垂直于x轴)
distan = 2*abs((b-b0));
else
{
distan = abs(((y-b0)*a-(x-a0)*b+b0*(x-a0)-a0*(y-b0))/sqrt((y-b0)*(y-b0)+(x-a0)*(x-a0)));//圆心到达直线的距离
//cout<<"((y-b)*a-(x-a)*b+b*(x-a)-a*(y-b)):"<<((y-b0)*a-(x-a0)*b+b0*(x-a0)-a0*(y-b0))<<endl;
//cout<<"sqrt((y-b)*(y-b)+(x-a)*(x-a)):"<<sqrt((y-b0)*(y-b0)+(x-a0)*(x-a0))<<endl;
//cout<<"distan:"<<distan<<endl;
distance = 2*sqrt(r*r-distan*distan);//直线被元所截得长度
}
//cout<<distance<<endl;
cout<<fixed<<setprecision(2)<<distance<<endl;
}
return 0;
}
解题思路:
点到直线的距离,勾股定理