HDU1174+三维点到直线距离
点B到直线AC的距离 就是 |AB X AC|/|AC| ‘X’是叉乘 ’ || ‘表示模
View Code
1 /* 2 三维+点到直线的距离 3 */ 4 #include<stdio.h> 5 #include<string.h> 6 #include<stdlib.h> 7 #include<algorithm> 8 #include<iostream> 9 #include<queue> 10 //#include<map> 11 #include<math.h> 12 using namespace std; 13 typedef long long ll; 14 //typedef __int64 int64; 15 const int maxn = 105; 16 const int inf = 0x7fffffff; 17 const double pi=acos(-1.0); 18 const double eps = 1e-8; 19 struct point { 20 double x,y,z; 21 }; 22 struct line{ 23 double a,b,c,d; 24 };//ax+by+cz+d=0; 25 struct people{ 26 double hi,r,x,y,z; 27 }; 28 double fpow( double x ){ 29 return x*x; 30 } 31 int main(){ 32 int ca; 33 scanf("%d",&ca); 34 while( ca-- ){ 35 people police,thief; 36 point new_one,new_two; 37 scanf("%lf%lf%lf%lf%lf",&thief.hi,&thief.r,&thief.x,&thief.y,&thief.z); 38 scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&police.hi,&police.r,&police.x,&police.y,&police.z,&new_two.x,&new_two.y,&new_two.z); 39 40 thief.z = thief.z+thief.hi-thief.r ; 41 police.z = police.z+0.9*police.hi-police.r ; 42 new_one.x = thief.x - police.x; 43 new_one.y = thief.y - police.y; 44 new_one.z = thief.z - police.z;//警察与小偷之间的向量 45 double tmp0,tmp1,tmp2; 46 tmp0=new_one.y*new_two.z-new_one.z*new_two.y; 47 tmp1=-new_one.x*new_two.z+new_one.z*new_two.x; 48 tmp2=new_one.x*new_two.y-new_one.y*new_two.x; 49 double sum; 50 sum = sqrt( fpow(tmp0)+fpow(tmp1)+fpow(tmp2) ); 51 double ans; 52 ans = sum/sqrt(fpow(new_two.x)+fpow(new_two.y)+fpow(new_two.x)); 53 //printf("%lf %lf\n",ans,thief.r); 54 if( ans<=thief.r && (new_one.x*new_two.x+new_one.y*new_two.y+new_one.z*new_two.z)>0 ) 55 printf("YES\n"); 56 else 57 printf("NO\n"); 58 } 59 return 0; 60 }
keep moving...