Distance from space point to line (hdu1174 headshot)

head shot

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2827    Accepted Submission(s): 1344


Problem Description
gameboy is a CS master, his favorite is to play the policeman, holding the M4 to blast the head of the bandit. Maybe someone here has never played CS, and it is necessary to introduce the term "headshot": the so-called headshot is a bullet that directly hits the opponent's head to kill the enemy in seconds.

Now use a three-dimensional Cartesian coordinate system to describe the three-dimensional space in the game (the horizontal plane is the xoy plane, and the positive direction of the z-axis is up). Suppose the character's head in the game is a standard ball. Tell you the height of the bandit, the radius of the head, the coordinates of the position where he is standing; the height of the policeman controlled by gameboy, the radius of the head, the coordinates of the position where he is standing, and the unit vector of the direction the gun head points to. The policeman charged by the gameboy is holding an M4. The bullets in the gun chamber are basically on the same line as the line of sight when aiming, and we ignore their distance and treat them as the same line. Since the bandit was holding an AK47, he was standing upright arrogantly. The policeman is holding an M4 and is aiming. Since his body is slightly bent when aiming, his line of sight starts from the center of his head. The actual height of his head is 10% lower than when he is standing upright.

Your task is to calculate whether the gameboy can explode the bandit's head when he pulls the trigger at this moment. Note: The diameter and gravity of the bullet are ignored here, which means that the bullet is infinitely small, the trajectory is a straight ray, and there is no obstacle between the police and the bandits. And as long as the bullet rubs the head, even at the edge, it counts as a headshot.
 

Input
The first line of the test data has a positive integer T, indicating that there are T groups of test data. The first line of each set of data has five real numbers, h1, r1, x1, y1, z1, which represent the bandit's height, head radius, and standing position, respectively. There are eight real numbers in the second line, h2, r2, x2, y2, z2, x3, y3, z3, which represent the policeman's height, head radius, standing position, and the direction vector of the direction the gun head points.
 

Output
Each set of input data corresponds to a line of output. If the bandit's head can be exploded, output "YES", otherwise output "NO".
 

Sample Input
 
  
2 1.62 0.1 10.0 10.0 10.0 1.80 0.09 0.0 0.0 0.0 1.0 1.0 1.0 1.62 0.1 0.0 0.0 0.0 1.80 0.09 10.0 10.0 10.0 -1.0 -1.0 -1.0
 

Sample Output
 
  
YES YES
 

Gives you the height, head radius, coordinates of cops and bandits standing in 3D space. And also the direction vector of the police gun

Determine if you can headshot

Supplementary knowledge:

difference multiplication

Vector a=(x1,y1,z1) b=(x2,y2,z2)

ax(difference multiplication) b=( y1z2 - z1y2 , z1x2 - x1z2 , x1y2-y1x2)

The distance from the point to the line can be calculated using the equal area

The distance from B to the straight line AC can be multiplied by |AB difference AC|/|AC|

[csharp]  view plain copy  
  1. #include<stdio.h>  
  2. #include<math.h> 
  3. intmain  ()  
  4. {  
  5.     int t;  
  6.     double h1,r1,x1,y1,z1;  
  7.     double h2,r2,x2,y2,z2;  
  8.     double x3,y3,z3;  
  9.     double x,y,z;  
  10.     double dis,a,b,c;  
  11.     scanf("%d",&t);  
  12.     while(t--)  
  13.     {  
  14.         scanf("%lf%lf%lf%lf%lf",&h1,&r1,&x1,&y1,&z1);  
  15.         scanf("%lf%lf%lf%lf%lf",&h2,&r2,&x2,&y2,&z2);  
  16.         scanf("%lf%lf%lf",&x3,&y3,&z3);  
  17.         z1=z1+h1-r1; //The Z coordinate of the bandit head  
  18.         z2=z2+h2*0.9-r2; //The Z-axis coordinate of the policeman's head  
  19.         x=x1-x2; //The connection vector between the bandit's head and the policeman's head  
  20.         y=y1-y2;  
  21.         z=z1-z2;  
  22.         a=y*z3-z*y3; //Multiply the difference between the direction vector of the pistol and the line connecting the police and the bandit  
  23.         b=z*x3-x*z3;  
  24.         c=x*y3-y*x3;  
  25.         dis=sqrt((a*a+b*b+c*c)/(x3*x3+y3*y3+z3*z3));  
  26.         if (dis<=r1&&(x*x3+y*y3*z*z3>0)) r1 can also be written as r2, and the red part is to judge that the bandit is in front of the police rather than behind. .  
  27.             printf("YES\n");  
  28.         else  
  29.             printf("NO\n");  
  30.     }  
  31.     return 0;  
  32. }  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325945473&siteId=291194637