fork(1) download
  1. import math
  2. def crossP(a,b,c):
  3. c[0]=a[1]*b[2]-a[2]*b[1]
  4. c[1]=a[2]*b[0]-a[0]*b[2]
  5. c[2]=a[0]*b[1]-a[1]*b[0]
  6.  
  7. def distance(x1,y1,z1,x2,y2,z2):
  8. return math.sqrt((x2-x1)**2+(y2-y1)**2+(z2-z1)**2)
  9.  
  10. def getMagnitude(a):
  11. return math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2])
  12.  
  13. def getQ(q,t,d):
  14. return [(q[0]+(d[0]*t)),(q[1]+(d[1]*t)),(q[2]+(d[2]*t))]
  15.  
  16. def intersects(q,p,c,r):
  17. cp,cq=[c[0]-p[0],c[1]-p[1],c[2]-p[2]],[c[0]-q[0],c[1]-q[1],c[2]-q[2]]
  18. CP=[0,0,0]
  19. crossP(cp,cq,CP)
  20. CP=getMagnitude(CP)
  21. d=distance(q[0],q[1],q[2],p[0],p[1],p[2])
  22. return True if ((CP/d)<r) else False
  23.  
  24. def bs(low,high,p,q,r,d,c):
  25. ans=0
  26. mid=0
  27. count=100
  28. while(count):
  29. mid=(low+high)/2
  30. q1=getQ(q,mid,d)
  31. if(intersects(q1,p,c,r)):
  32. low=mid
  33. else:
  34. ans,high=mid,mid
  35. count-=1
  36. return ans
  37.  
  38. def main():
  39. t=int(input())
  40. for _ in range(t):
  41. px,py,pz,qx,qy,qz,dx,dy,dz,cx,cy,cz,r=map(int,input().split())
  42. p=[px,py,pz]
  43. c=[cx,cy,cz]
  44. q=[qx,qy,qz]
  45. d=[dx,dy,dz]
  46. ans=bs(0,1000000000,p,q,r,d,c)
  47. print(ans)
  48.  
  49. main()
  50.  
Success #stdin #stdout 0.04s 9704KB
stdin
1
3 0 0 -10 -10 0 0 10 0 0 -3 0 3
stdout
1.0