A purely mathematical problem, figure out the distance between space and a space line
The point equation (x-x2)/a= (y-y2)/b= (Z-Z2)/c=tt, which describes the line which can be written out by the topic
then calculate the plane of the point perpendicular to the line, (A,B,C) is the normal vector of the plane, so A * (x-x1) +b* (y-y1) +c* (Z-Z1) =0
calculates the point where the space line intersects the plane A * (a*tt+x2-x1) +b* (b*tt+y2-y1) +c* (C*TT+Z2-Z1) =0
figure out tt= (A * (X1-X2) +b* (y1-y2) +c* (Z1-Z2))/(A*A+B*B+C*C) the intersection is (a*tt+x2,b*tt+y2,c*tt+z2 )
the distance between the intersection and the point given by the topic (that is, the head heart of the Bandit) is the distance. Then determine if the distance is less than the head radius of the headshot. Otherwise the head will not explode.
#include <iostream>
using namespace std;
int main () {
int t;
cin>>t;
while (t--)
{
double h1,h2,x1,x2,y1,y2,z1,z2,a,b,c,r1,r2;
Cin>>h1>>r1>>x1>>y1>>z1>>h2>>r2>>x2>>y2>>z2> >a>>b>>c;
Z2+=H2*0.9-R2; Z2,Z1 is the height of the human foot, so to get the head heart height to add so much.
z1+=h1-r1;
Double Tt= (A * (X1-X2) +b* (y1-y2) +c* (Z1-Z2))/(A*A+B*B+C*C);
Double x=a*tt+x2,y=b*tt+y2,z=c*tt+z2;
if ((x-x1) * (x-x1) + (y-y1) * (y-y1) + (Z-Z1) * (Z-Z1) <=r1*r1) printf ("yes\n");
else printf ("no\n");
}
return 0;
}