Old fashion design for PC-104
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.

118 lines
3.7 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: Transform.cpp
  9. // AUTHOR: Belkovsky Joseph
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of Transform.cpp
  13. //----------------------------------------------------------------------------
  14. // Transform.cpp : Defines the entry point for the console application.
  15. //
  16. #include "stdafx.h"
  17. #include "..\LgLib\Version.h"
  18. #include "transform.h"
  19. const double transform_3::PI_M = 3.141592653589793;
  20. const double transform_3::DTOR = 0.017453292519943;
  21. const double transform_3::RTOD = 57.29577951308232;
  22. vector_3::vector_3(double a0, double a1, double a2)
  23. {
  24. elem_[0] = a0;
  25. elem_[1] = a1;
  26. elem_[2] = a2;
  27. }
  28. matrix_3::matrix_3(double a00, double a01, double a02,
  29. double a10, double a11, double a12,
  30. double a20, double a21, double a22)
  31. {
  32. elem_[0][0] = a00; elem_[0][1] = a01; elem_[0][2] = a02;
  33. elem_[1][0] = a10; elem_[1][1] = a11; elem_[1][2] = a12;
  34. elem_[2][0] = a20; elem_[2][1] = a21; elem_[2][2] = a22;
  35. }
  36. matrix_3 matrix_3::operator * (const matrix_3& matrix) const
  37. {
  38. matrix_3 result;
  39. for(__int8 ii = 0; ii < 3; ++ii)
  40. for(__int8 jj = 0; jj < 3; ++jj)
  41. for(__int8 kk = 0; kk < 3; ++kk)
  42. result.elem_[ii][jj] += elem_[ii][kk] * matrix.elem_[kk][jj];
  43. return result;
  44. }
  45. vector_3 matrix_3::operator * (const vector_3& vector) const
  46. {
  47. vector_3 result;
  48. for(__int8 ii = 0; ii < 3; ++ii)
  49. for(__int8 jj = 0; jj < 3; ++jj)
  50. result[ii] += elem_[ii][jj] * vector[jj];
  51. return result;
  52. }
  53. vector_3 operator * (const vector_3& vector, const matrix_3& matrix)
  54. {
  55. vector_3 result;
  56. for(__int8 ii = 0; ii < 3; ++ii)
  57. for(__int8 jj = 0; jj < 3; ++jj)
  58. result[ii] += matrix.elem_[jj][ii] * vector[jj];
  59. return result;
  60. }
  61. matrix_3 operator * (double scalar, const matrix_3& matrix)
  62. {
  63. matrix_3 result = matrix;
  64. for(__int8 ii = 0; ii < 3; ++ii)
  65. for(__int8 jj = 0; jj < 3; ++jj)
  66. result.elem_[ii][jj] *= scalar;
  67. return result;
  68. }
  69. transform_3::transform_3(double Xc, double Yc, double Zc,
  70. double Psicd, double Thetacd, double Phicd)
  71. : core_matrix_(1, 0, 0,
  72. 0, cos(DTOR * Phicd), sin(DTOR * Phicd),
  73. 0, -sin(DTOR * Phicd), cos(DTOR * Phicd)), // Phic matrix
  74. core_vector_(Xc, Yc, Zc)
  75. {
  76. // Rotation by Thetac matrix
  77. core_matrix_ *= matrix_3(cos(DTOR * Thetacd), 0, -sin(DTOR * Thetacd),
  78. 0, 1, 0,
  79. sin(DTOR * Thetacd), 0, cos(DTOR * Thetacd));
  80. // Rotation by Psic matrix
  81. core_matrix_ *= matrix_3(cos(DTOR * Psicd), sin(DTOR * Psicd), 0,
  82. -sin(DTOR * Psicd), cos(DTOR * Psicd), 0,
  83. 0, 0, 1);
  84. }
  85. void transform_3::get_ptz_params(double angle, double range, ptz_params& params)
  86. {
  87. double theta_t_s = .0; // Assume that the tilt ot the target is 0[deg].
  88. // Latter we can put as the tilt of the LRF
  89. // Transformation to camera system, r_t_c = Target vector in camera system [m]
  90. vector_3 r_t_c = core_matrix_ * (range * vector_3(cos(DTOR * angle) * cos(theta_t_s),
  91. sin(DTOR * angle) * cos(theta_t_s),
  92. -sin(theta_t_s)) - core_vector_);
  93. params.pan = static_cast<float> (RTOD * atan2(r_t_c[1], r_t_c[0])); // Pan, in degree
  94. params.tilt = static_cast<float> (RTOD * atan2(-r_t_c[2], sqrt(r_t_c[0] * r_t_c[0] + r_t_c[1] * r_t_c[1]))); // Tilt, in degree
  95. params.dist = static_cast<float> (sqrt(r_t_c * r_t_c)); // Range, in meters
  96. }