我仍然相信变换矩阵对你来说会是更好的方法。
如前面的问题所提到的,欧拉角并不适合你的目的,只会让事情变得混乱。但无论如何,你觉得这个怎么样:
P0=(0,0,0)
P1=(1,0,0) // or (0,0,1) y=0 !!!
A0=r2_localtoglobal(P0)
A1=r2_localtoglobal(P1)
B0=r2r1_localtoglobal(P0)
B1=r2r1_localtoglobal(P1)
A=A1-A0 // local r2 X axis direction in GCS (without r1)
B=B1-B0 // local r2r1 X axis direction in GCS (with r1)
angle=-acos((A.B)/(|A|.|B|)) // angle between A,B (but inverted because you wanted local angle)
我假设
r1
代表船,
r2
代表雷达。
[编辑1] 阅读您链接问题的编辑后,现在我终于清楚你想要什么了。
P0=(0,0,0)
P1=(1,0,0) // or (0,0,1) y=0 !!!
A0=r1_globaltolocal(P0)
A1=r1_globaltolocal(P1)
A=A1-A0
angle=atanxy(A.x,A.z)
- 其中
r1
是您的船只变换
- 雷达变换与背景图像无关
atanxy
是atan2(y,x) = atan(y/x)
,但具有符号分解,因此它适用于整个< 0,2PI >
区间
atan2,atanxy:
const double pi=M_PI;
const double pi2=2.0*M_PI;
double atanxy(double x,double y)
{
int sx,sy;
double a;
const double _zero=1.0e-30;
sx=0; if (x<-_zero) sx=-1; if (x>+_zero) sx=+1;
sy=0; if (y<-_zero) sy=-1; if (y>+_zero) sy=+1;
if ((sy==0)&&(sx==0)) return 0;
if ((sx==0)&&(sy> 0)) return 0.5*pi;
if ((sx==0)&&(sy< 0)) return 1.5*pi;
if ((sy==0)&&(sx> 0)) return 0;
if ((sy==0)&&(sx< 0)) return pi;
a=y/x; if (a<0) a=-a;
a=atan(a);
if ((x>0)&&(y>0)) a=a;
if ((x<0)&&(y>0)) a=pi-a;
if ((x<0)&&(y<0)) a=pi+a;
if ((x>0)&&(y<0)) a=pi2-a;
return a;
}
r3 = r2.r1
然后T1 = r1.T0
和T2 = r2.T1
,然后T2 = r2.r1.T0
,即T2 = r3.T0
。 - Felix Castor