You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
7.0 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
7 years ago
​
  1. #include "basicPosition.h"
  2. #include "string.h"
  3. position3D::position3D() {
  4. x = y = z = lat = lon = rot_z = rot_y = rot_z = speed = 0.f;
  5. utmZone = 0;
  6. };
  7. position3D::position3D( C3D_WGS84_LOC loc, C3D_SPH_DEGREES orient ){
  8. coordConverter CC;
  9. lat = loc.lat;
  10. lon = loc.lon;
  11. z = loc.alt;
  12. #ifdef FLOAT_64
  13. double A, B;
  14. CC.LatLonToUTMXY(lat, lon, utmZone, A, B);
  15. x = A;
  16. y = B;
  17. #else
  18. CC.LatLonToUTMXY(lat, lon, utmZone, x, y);
  19. #endif
  20. };
  21. position3D::position3D( C3D_WGS84_LOC loc, C3D_SPH_RADIANS orient ){
  22. coordConverter CC;
  23. lat = loc.lat;
  24. lon = loc.lon;
  25. z = loc.alt;
  26. #ifdef FLOAT_64
  27. double A, B;
  28. CC.LatLonToUTMXY(lat, lon, utmZone, A, B);
  29. x = A;
  30. y = B;
  31. #else
  32. CC.LatLonToUTMXY(lat, lon, utmZone, x, y);
  33. #endif
  34. rot_x = orient.r;
  35. rot_y = orient.fi;
  36. rot_z = orient.tetta;
  37. };
  38. position3D::position3D( int UTM_Zone, C3D_DECART loc, C3D_SPH_DEGREES orient ){
  39. coordConverter CC;
  40. utmZone = UTM_Zone;
  41. x = loc.x;
  42. y = loc.y;
  43. z = loc.z;
  44. #ifdef FLOAT_64
  45. double A, B;
  46. CC.UTMXYToLatLon(x, y, utmZone, A, B);
  47. lat = A;
  48. lon = B;
  49. #else
  50. CC.UTMXYToLatLon(x, y, utmZone, false, lat, lon);
  51. #endif
  52. rot_x = deg2rad(orient.r);
  53. rot_y = deg2rad(orient.fi);
  54. rot_z = deg2rad(orient.tetta);
  55. };
  56. position3D::position3D( int UTM_Zone, C3D_DECART loc, C3D_SPH_RADIANS orient ){
  57. coordConverter CC;
  58. utmZone = UTM_Zone;
  59. x = loc.x;
  60. y = loc.y;
  61. z = loc.z;
  62. #ifdef FLOAT_64
  63. double A, B;
  64. CC.UTMXYToLatLon(x, y, utmZone, A, B);
  65. lat = A;
  66. lon = B;
  67. #else
  68. CC.UTMXYToLatLon(x, y, utmZone, false, lat, lon);
  69. #endif
  70. };
  71. position3D::~position3D() {
  72. };
  73. void position3D::setPositionWGS84(C3D_FLOAT Lat, C3D_FLOAT Lon, C3D_FLOAT Alt) {
  74. coordConverter CC;
  75. lat = Lat;
  76. lon = Lon;
  77. z = Alt;
  78. #ifdef FLOAT_64
  79. double A, B;
  80. CC.LatLonToUTMXY(lat, lon, utmZone, A, B);
  81. x = A;
  82. y = B;
  83. #else
  84. CC.LatLonToUTMXY(lat, lon, utmZone, x, y);
  85. #endif
  86. };
  87. void position3D::setPositionXYZ(C3D_FLOAT X, C3D_FLOAT Y, C3D_FLOAT Z, int zone) {
  88. coordConverter CC;
  89. if (zone != 0) utmZone = zone;
  90. x = X;
  91. y = Y;
  92. z = Z;
  93. #ifdef FLOAT_64
  94. double A, B;
  95. CC.UTMXYToLatLon(x, y, utmZone, false, A, B);
  96. lat = A;
  97. lon = B;
  98. #else
  99. CC.UTMXYToLatLon(x, y, utmZone, false, lat, lon);
  100. #endif
  101. };
  102. C3D_WGS84_LOC position3D::getWGS84( void ){
  103. C3D_WGS84_LOC retVal;
  104. retVal.lat = lat;
  105. retVal.lon = lon;
  106. retVal.alt = z;
  107. return retVal;
  108. };
  109. C3D_DECART position3D::getXYZ( void ){
  110. C3D_DECART retVal;
  111. retVal.x = x;
  112. retVal.y = y;
  113. retVal.z = z;
  114. return retVal;
  115. };
  116. void position3D::setOrientationRad(C3D_FLOAT RotX, C3D_FLOAT RotY, C3D_FLOAT RotZ) {
  117. rot_x = RotX;
  118. rot_y = RotY;
  119. rot_z = RotZ;
  120. };
  121. void position3D::setOrientationDeg(C3D_FLOAT RotX, C3D_FLOAT RotY, C3D_FLOAT RotZ) {
  122. rot_x = deg2rad(RotX);
  123. rot_y = deg2rad(RotY);
  124. rot_z = deg2rad(RotZ);
  125. };
  126. void position3D::setSpeed(C3D_FLOAT Speed) {
  127. speed = Speed;
  128. };
  129. // Constructor implementation
  130. basicPosition::basicPosition(): position3D() {
  131. m_pTransform = NULL;
  132. updateMatrix();
  133. };
  134. basicPosition::basicPosition(const basicPosition& src){
  135. memcpy(this, &src, sizeof(basicPosition));
  136. updateMatrix();
  137. };
  138. basicPosition& basicPosition::operator=(const basicPosition& src){
  139. if( this == &src ){
  140. return *this;
  141. };
  142. memcpy(this, &src, sizeof(basicPosition));
  143. updateMatrix();
  144. return *this;
  145. };
  146. basicPosition::basicPosition( C3D_WGS84_LOC loc, C3D_SPH_DEGREES orient ): position3D( loc, orient ){
  147. m_pTransform = NULL;
  148. position3D::setSpeed( 0.0f );
  149. updateMatrix();
  150. };
  151. basicPosition::basicPosition( C3D_WGS84_LOC loc, C3D_SPH_RADIANS orient ): position3D( loc, orient ){
  152. m_pTransform = NULL;
  153. position3D::setSpeed( 0.0f );
  154. updateMatrix();
  155. };
  156. basicPosition::basicPosition( int UTM_Zone, C3D_DECART loc, C3D_SPH_DEGREES orient ): position3D( UTM_Zone, loc, orient ){
  157. m_pTransform = NULL;
  158. position3D::setSpeed( 0.0f );
  159. updateMatrix();
  160. };
  161. basicPosition::basicPosition( int UTM_Zone, C3D_DECART loc, C3D_SPH_RADIANS orient ): position3D( UTM_Zone, loc, orient ){
  162. m_pTransform = NULL;
  163. position3D::setSpeed( 0.0f );
  164. updateMatrix();
  165. };
  166. basicPosition::basicPosition( float Lat, float Lon, float Alt, float h_lat, float h_lon, float h_alt, float Speed ) : position3D() {
  167. m_pTransform = NULL;
  168. position3D::setPositionWGS84( Lat, Lon, Alt );
  169. position3D::setOrientationRad( h_lat, h_lon, h_alt );
  170. position3D::setSpeed( Speed );
  171. updateMatrix();
  172. };
  173. void basicPosition::setPositionRad(float Lat, float Lon, float Alt, float h_lat, float h_lon, float h_alt, float Speed ){
  174. position3D::setPositionWGS84(Lat, Lon, Alt);
  175. position3D::setOrientationRad(h_lat, h_lon, h_alt);
  176. position3D::setSpeed(Speed);
  177. updateMatrix();
  178. };
  179. void basicPosition::setPositionDeg(float Lat, float Lon, float Alt, float h_lat, float h_lon, float h_alt, float Speed){
  180. position3D::setPositionWGS84(Lat, Lon, Alt);
  181. position3D::setOrientationDeg(h_lat, h_lon, h_alt);
  182. position3D::setSpeed(Speed);
  183. updateMatrix();
  184. };
  185. void basicPosition::updateMatrix( void ){
  186. //Tait-Bryan angles
  187. //X1Y2Z3
  188. // C2C3 -C2S3 S2
  189. // C1S3+C3S1S2 C1C3-S1S2S3 -C2S1
  190. // S1S3-C1C3S2 C3S1+C1S2S3 C1C2
  191. if( m_pTransform != NULL ){
  192. delete( m_pTransform );
  193. m_pTransform = NULL;
  194. };
  195. m_pTransform = new transform_3( x, y, z, rot_x, rot_y, rot_z );
  196. /*
  197. float X, Z, Y;
  198. X = rot_x;
  199. Y = rot_y;
  200. Z = rot_z;
  201. //m_sMatrix.AA = cosf(Y)*cosf(P) - sinf(P)*cosf(R)*sinf(Y);
  202. //m_sMatrix.AB = -cosf(P)*sinf(Y) - sinf(P)*cosf(R)*cosf(Y);
  203. //m_sMatrix.AC = sinf(P)*sinf(R);
  204. m_sMatrix.AA = cosf(Y)*cosf(Z);
  205. m_sMatrix.AB = -sinf(Z);
  206. m_sMatrix.AC = sinf(Y);
  207. m_sMatrix.AD = x;
  208. //m_sMatrix.BA = sinf(P)*cosf(Y) + cosf(P)*cosf(R)*sinf(Y);
  209. //m_sMatrix.BB = -sinf(P)*sinf(Y) + cosf(P)*cosf(R)*cosf(Y);
  210. //m_sMatrix.BC = -cosf(P)*sinf(R);
  211. m_sMatrix.BA = sinf(Z);
  212. m_sMatrix.BB = cosf(Z)*cosf(X);
  213. m_sMatrix.BC = -sinf(X);
  214. m_sMatrix.BD = y;
  215. //m_sMatrix.CA = sinf(R)*sinf(Y);
  216. //m_sMatrix.CB = sinf(R)*cosf(Y);
  217. //m_sMatrix.CC = cosf(R);
  218. m_sMatrix.CA = -sinf(Y);
  219. m_sMatrix.CB = sinf(X);
  220. m_sMatrix.CC = cosf(X)*cosf(Y);
  221. m_sMatrix.CD = z;
  222. m_sMatrix.DA = -x;
  223. m_sMatrix.DB = -y;
  224. m_sMatrix.DC = -z;
  225. m_sMatrix.DD = 1.f;
  226. */
  227. };
  228. /*
  229. void basicPosition::convertLocalXYZ( C3D_DECART POS, C3D_SPH_DEGREES& LO� ){
  230. float T = (POS.x*POS.x)+(POS.y*POS.y);
  231. LOC.r = sqrtf(T+(POS.z*POS.z));
  232. if( POS.x > 0 ) {
  233. LOC.fi = 1 / tanf( POS.y / POS.x );
  234. } else LOC.fi = 0;
  235. if( POS.z > 0 ) {
  236. LOC.teta = 1 / tanf( sqrtf( T ) / POS.z );
  237. } else LOC.teta = 0;
  238. LOC = rad2deg( TT );
  239. };
  240. void basicPosition::convertLocalXYZ( C3D_DECART POS, C3D_SPH_RADIANS& LO� ){
  241. float T = (POS.x*POS.x)+(POS.y*POS.y);
  242. LOC.r = sqrtf(T+(POS.z*POS.z));
  243. if( POS.x > 0 ) {
  244. LOC.fi = 1 / tanf( POS.y / POS.x );
  245. } else LOC.fi = 0;
  246. if( POS.z > 0 ) {
  247. LOC.teta = 1 / tanf( sqrtf( T ) / POS.z );
  248. } else LOC.teta = 0;
  249. };
  250. */
  251. // Destructor implementation
  252. basicPosition::~basicPosition(){
  253. };