1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <bits/stdc++.h>
#include<iostream>
#include<math.h>
#define DB long double
using namespace std;
DB dot_product_result(DB x1,DB y1, DB z1, DB x2, DB y2, DB z2)
{
DB result1= x1*x2+y1*y2+z1*z2;
return result1;
}
int main()
{
DB t,p1,p2,p3,q1,q2,q3,d1,d2,d3,c1,c2,c3,r;
cin>>t;
while(t--)
{
cin>>p1>>p2>>p3>>q1>>q2>>q3>>d1>>d2>>d3>>c1>>c2>>c3>>r;
DB constant1= dot_product_result(q1-p1,q2-p2,q3-p3,q1-p1,q2-p2,q3-p3 );
DB constant2= 2*dot_product_result( q1-p1,q2-p2,q3-p3,d1,d2,d3);
DB constant3= dot_product_result(d1,d2,d3,d1,d2,d3);
DB constant1_1= dot_product_result(q1-p1,q2-p2,q3-p3,c1-p1,c2-p2,c3-p3);
DB constant2_2= dot_product_result(d1,d2,d3,c1-p1,c2-p2,c3-p3);
DB term1= dot_product_result(c1-p1,c2-p2,c3-p3,c1-p1,c2-p2,c3-p3);
DB a= r*r*constant3- term1*constant3+ constant2_2*constant2_2;
DB b= r*r*constant2-term1*constant2+ 2*constant1_1*constant2_2;
DB c= r*r*constant1- term1*constant1+constant1_1*constant1_1;
if(a==0.0)
cout<<fixed<<setprecision(6)<<-c/b<<endl;
else {
DB time1,time2,t;
DB a = (-b/(2*a))/(2*a);
DB b = (sqrt(b*b-4*a*a))/(2*a);
time1 = a+b;
time2 = a-b;
if (time1<0)
cout<<fixed<<setprecision(6)<<time2<<endl;
else if(time2<0)
cout<<fixed<<setprecision(6)<<time1<<endl;
else if(time1>=0 && time2>=0)
cout<<fixed<<setprecision(6)<<min(time1,time2)<<endl;
}
}
}
|