coordinates.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #include "coordinates.h"
  2. /* 基本旋转矩阵 */
  3. void rot_x(demat* M, double alf) {
  4. //第1行元素
  5. M->v[0] = 1;
  6. M->v[1] = 0;
  7. M->v[2] = 0;
  8. //第2行元素
  9. M->v[3] = 0;
  10. M->v[4] = cos(alf);
  11. M->v[5] = sin(alf);
  12. //第3行元素
  13. M->v[6] = 0;
  14. M->v[7] = -sin(alf);
  15. M->v[8] = cos(alf);
  16. }
  17. void rot_y(demat* M, double alf) {
  18. //第1行元素
  19. M->v[0] = cos(alf);
  20. M->v[1] = 0;
  21. M->v[2] = -sin(alf);
  22. //第2行元素
  23. M->v[3] = 0;
  24. M->v[4] = 1;
  25. M->v[5] = 0;
  26. //第3行元素
  27. M->v[6] = sin(alf);
  28. M->v[7] = 0;
  29. M->v[8] = cos(alf);
  30. }
  31. void rot_z(demat* M, double alf) {
  32. //第1行元素
  33. M->v[0] = cos(alf);
  34. M->v[1] = sin(alf);
  35. M->v[2] = 0;
  36. //第2行元素
  37. M->v[3] = -sin(alf);
  38. M->v[4] = cos(alf);
  39. M->v[5] = 0;
  40. //第3行元素
  41. M->v[6] = 0;
  42. M->v[7] = 0;
  43. M->v[8] = 1;
  44. }
  45. /* 由基本旋转矩阵衍生的各个坐标系直接的旋转矩阵 */
  46. void C_A2B(demat* M, double phi_T, double psi_T, double gamma_T) {
  47. // 返回或者发射惯性系到飞行器体坐标系
  48. // phi_T, psi_T, gamma_T: 321转序,返回惯性坐标系到体坐标系的姿态角;
  49. // 转序:321
  50. demat* M1, * M2;
  51. M1 = createDeMat(3, 3);
  52. M2 = createDeMat(3, 3);
  53. rot_z(M1, phi_T);
  54. rot_y(M, psi_T);
  55. denseMM(M2, M, M1);
  56. rot_x(M1, gamma_T);
  57. denseMM(M, M1, M2);
  58. freeDeMat(M1, 2);
  59. freeDeMat(M2, 2);
  60. }
  61. void C_A2O(demat* M, double A0, double phi0, double T) {
  62. // 返回惯性系到返回系
  63. // A0: 初始方位角
  64. // phi0: 初始地心或者地理纬度
  65. // T:从建立再入坐标系的时刻起的飞行时间
  66. double we;
  67. demat* M1, * M2;
  68. we = 7.272205216643040e-05; // 地球自转角速度,rad / s
  69. M1 = createDeMat(3, 3);
  70. M2 = createDeMat(3, 3);
  71. C_O2E(M1, A0, phi0);
  72. rot_z(M, we * T);
  73. denseMM(M2, M, M1);
  74. denseMtM(M, M1, M2);
  75. freeDeMat(M1, 2);
  76. freeDeMat(M2, 2);
  77. }
  78. void C_En2T(demat* M, double phi0, double phi, double dlambda) {
  79. // 再入坐标系到地理坐标系之间的转换
  80. // phi0 : 再入坐标系原点的地心或者地理纬度
  81. // phi : 地理坐标系原点的地心纬度
  82. // dlambda : 经度差
  83. demat* M1, * M2;
  84. M1 = createDeMat(3, 3);
  85. M2 = createDeMat(3, 3);
  86. rot_z(M1, phi0);
  87. rot_x(M, dlambda);
  88. denseMM(M2, M, M1);
  89. rot_z(M1, -phi);
  90. denseMM(M, M1, M2);
  91. freeDeMat(M1, 2);
  92. freeDeMat(M2, 2);
  93. }
  94. void C_H2B(demat* M, double nv, double beta, double alpha) {
  95. // 半速度坐标系到飞行器体坐标系之间的转换
  96. // 转序:123转序
  97. // nv:倾侧角
  98. // beta:侧滑角
  99. // alpha: 攻角
  100. demat* M1, * M2;
  101. M1 = createDeMat(3, 3);
  102. M2 = createDeMat(3, 3);
  103. rot_x(M1, nv);
  104. rot_y(M, beta);
  105. denseMM(M2, M, M1);
  106. rot_z(M1, alpha);
  107. denseMM(M, M1, M2);
  108. freeDeMat(M1, 2);
  109. freeDeMat(M2, 2);
  110. }
  111. void C_O2E(demat* M, double A0, double phi0) {
  112. // 返回系到地心坐标系
  113. // A0: 初始方位角
  114. // phi0: 初始地心或者地理纬度
  115. demat* M1, * M2;
  116. M1 = createDeMat(3, 3);
  117. M2 = createDeMat(3, 3);
  118. rot_y(M1, A0 + PI / 2);
  119. rot_x(M, -phi0);
  120. denseMM(M2, M, M1);
  121. rot_z(M1, PI / 2);
  122. denseMM(M, M1, M2);
  123. freeDeMat(M1, 2);
  124. freeDeMat(M2, 2);
  125. }
  126. void C_O2En(demat* M, double A0) {
  127. // 返回系到再入坐标系之间的转换
  128. // A0:初始方位角
  129. rot_y(M, A0);
  130. }
  131. void C_T2H(demat* M, double sigma, double theta) {
  132. // 地理坐标系到半速度坐标系之间的转换
  133. // 转序:23转序
  134. // sigma:负当地航迹方位角
  135. // theta:当地速度倾角
  136. demat* M1, * M2;
  137. M1 = createDeMat(3, 3);
  138. M2 = createDeMat(3, 3);
  139. rot_y(M1, sigma);
  140. rot_z(M2, theta);
  141. denseMM(M, M2, M1);
  142. freeDeMat(M1, 2);
  143. freeDeMat(M2, 2);
  144. }
  145. void C_V2B(demat* M, double beta, double alpha) {
  146. // 速度坐标系到飞行器体坐标系之间的转换
  147. // 转序:23
  148. // beta: 侧滑
  149. // alpha : 攻角
  150. demat* M1, * M2;
  151. M1 = createDeMat(3, 3);
  152. M2 = createDeMat(3, 3);
  153. rot_y(M1, alpha);
  154. rot_z(M2, beta);
  155. denseMM(M, M2, M1);
  156. freeDeMat(M1, 2);
  157. freeDeMat(M2, 2);
  158. }
  159. void A_H2B1(double* alpha, double* beta, double* nu,
  160. double sigma, double theta,
  161. double lat, double lon,
  162. double phi_T, double psi_T, double gamma_T,
  163. double A0, double lon0, double phi0, double T) {
  164. // alpha, beta, nu: 侧滑角, 攻角, 倾侧角
  165. //用方式1获得半速度坐标系H到飞行器体坐标系B之间的欧拉角
  166. //phi_T, psi_T, gamma_T: 321转序,返回惯性坐标系到体坐标系的姿态角;
  167. //theta:当地速度倾角;
  168. //sigma: 负的当地航迹方位
  169. //lon : 当前经度
  170. //lat : 当前纬度
  171. //A0 : 发射或者返回系的方位角
  172. //lon0 : 发射或者返回系原点经度、取决于坐标系怎么建立的
  173. //phi0 : 发射或者返回系原点地理或者地心纬度、取决于坐标系怎么建立的
  174. //T : 从建立返回系起的飞行时间
  175. demat* M1, * M2, * M3;
  176. M1 = createDeMat(3, 3);
  177. M2 = createDeMat(3, 3);
  178. M3 = createDeMat(3, 3);
  179. C_A2O(M1, A0, phi0, T);
  180. C_A2B(M3, phi_T, psi_T, gamma_T);
  181. denseMMt(M2, M3, M1); // M2 = C_O2B
  182. C_O2En(M1, A0);
  183. denseMMt(M3, M1, M2); // M3 = C_B2En
  184. C_En2T(M1, phi0, lat, lon - lon0);
  185. denseMM(M2, M1, M3); // M2 = C_B2T
  186. C_T2H(M1, sigma, theta);
  187. denseMM(M3, M1, M2); // M3 = C_B2H
  188. beta[0] = asin(M3->v[2]);
  189. alpha[0] = atan2(-M3->v[1], M3->v[0]);
  190. nu[0] = atan2(-M3->v[5], M3->v[8]);
  191. freeDeMat(M1, 2);
  192. freeDeMat(M2, 2);
  193. freeDeMat(M3, 2);
  194. }