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.

vectorxd.hxx 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <math.h>
  2. #define uge_gv_tmpl_x template<unsigned X>
  3. #define uge_gv_tmpl_xt template<unsigned X, class T>
  4. uge_gv_tmpl_x VectorXD<X>::MatrixMxN()
  5. {
  6. this->fill(0);
  7. }
  8. uge_gv_tmpl_x VectorXD<X>::MatrixMxN(double k)
  9. {
  10. this->fill(k);
  11. }
  12. uge_gv_tmpl_x VectorXD<X>::MatrixMxN(const double scalars[X])
  13. {
  14. this->fill(scalars);
  15. }
  16. uge_gv_tmpl_x VectorXD<X>::MatrixMxN(const VectorXD<X>& other)
  17. {
  18. for (unsigned i = 0; i < X; ++i) {
  19. _scalars[i] = other._scalars[i];
  20. }
  21. }
  22. uge_gv_tmpl_xt T& GenericVector<X, T>::setScalar(unsigned i, double value)
  23. {
  24. return setScalar(i, 0,value);
  25. }
  26. uge_gv_tmpl_xt double GenericVector<X, T>::getScalar(unsigned i) const
  27. {
  28. return getScalar(i, 0);
  29. }
  30. uge_gv_tmpl_xt double GenericVector<X, T>::operator[](unsigned i) const
  31. {
  32. return getScalar(i);
  33. }
  34. uge_gv_tmpl_xt double GenericVector<X, T>::dotProduct(const T &other) const
  35. {
  36. double total = 0;
  37. for (unsigned i = 0; i < X; ++i) {
  38. total += _scalars[i][0] * other._scalars[i][0];
  39. }
  40. return total;
  41. }
  42. uge_gv_tmpl_xt T& GenericVector<X, T>::crossProduct(const T& other)
  43. {
  44. T t = *getThis();
  45. for (unsigned i = 0; i < X; ++i) {
  46. unsigned j = (i + 1) % X;
  47. unsigned k = (i + 2) % X;
  48. _scalars[i][0] = (t._scalars[j][0] * other._scalars[k][0]) - (t._scalars[k][0] * other._scalars[j][0]);
  49. }
  50. return *getThis();
  51. }
  52. uge_gv_tmpl_xt T GenericVector<X, T>::crossProduct(const T &v1, const T &v2)
  53. {
  54. return T(v1).crossProduct(v2);
  55. }
  56. uge_gv_tmpl_xt double GenericVector<X, T>::norm() const
  57. {
  58. double total = 0;
  59. for (unsigned i = 0; i < X; ++i) {
  60. total += _scalars[i][0] * _scalars[i][0];
  61. }
  62. return sqrt(total);
  63. }
  64. uge_gv_tmpl_xt T* GenericVector<X, T>::getThis() const
  65. {
  66. return (T*)this;
  67. }