题意:给定若干望远镜的方向(望远镜都位于原点)和最大视角范围,求三维空间中指定的星星点能够被看到的个数
思路:求出星星向量和望远镜方向这两个向量的夹角,如果小于此望远镜的视角,则能够被看到
#include <stdio.h>
#include <string.h>
#include <math.h>
#define eps 1e-8
#define N 16
struct point{
double x,y,z;
}star[505],tele[55];
double angle[55];
int n,m;
double dis(struct point s){//向量的模长
return sqrt(s.x*s.x+s.y*s.y+s.z*s.z);
}
double dot(int a,int b){//两个向量夹角的余弦值
struct point q,p;
p = star[a];
q = tele[b];
return (p.x*q.x+p.y*q.y+p.z*q.z)/(dis(p)*dis(q));
}
int test(int a,int b){//判断星星的角度是否小于望远镜的角度
double temp = acos(dot(a,b));
if(temp-angle[b] < eps)
return 1;
return 0;
}
int main(){
freopen("a.txt","r",stdin);
while(scanf("%d",&n)&&n){
int i,j,res=0;
for(i = 0;i<n;i++)
scanf("%lf %lf %lf",&star[i].x,&star[i].y,&star[i].z);
scanf("%d",&m);
for(i = 0;i<m;i++)
scanf("%lf %lf %lf %lf",&tele[i].x,&tele[i].y,&tele[i].z,&angle[i]);
for(i = 0;i<n;i++)
for(j = 0;j<m;j++)
if(test(i,j)){
res++;
break;
}
printf("%d\n",res);
}
return 0;
}