三维相对angular度和计算

我有一个四元数forms的旋转r1的3D对象。 我用本地欧拉angular度旋转它:

transform.Rotate(new Vector3(0f, 15f, 0f), relativeTo: Space.Self); // right transform.Rotate(new Vector3(-10f, -5f, 0f), relativeTo: Space.Self); // left up transform.Rotate(new Vector3(0f, 0f, 90f), relativeTo: Space.Self); // 90 clockwise 

现在我有旋转r2 。 如果我不知道已经应用了什么angular度,我如何检索局部Y轴旋转总和15-5 + 0 = 10? 要得到这个价值可能是不可能的(10),但你有我的想法。 也许是我可以在当地的r2空间得到Y差异?

我发现一个可能的解决scheme

  (r2 * Quaternion.Inverse(r1)).eulerAngles.Y 

我仍然相信,变换matrix将是更好的方法给你

  • 如前面的问题所述
  • 欧拉angular不是最好的为你的目的,只是把事情搞砸了你
  • 但无论如何呢?

     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((AB)/(|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(Ax,Az) 
  • 其中r1是船舶改造
  • 雷达变换与背景图像无关
  • atanxy是atan2 = 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) // atan2 return < 0 , 2.0*M_PI > { 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; }