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.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <math.h>
  2. #define tmplx template<unsigned X>
  3. #define tmpl template<unsigned X, class T>
  4. tmplx VectorXD<X>::MatrixMxN()
  5. {
  6. this->fill(0);
  7. }
  8. tmplx VectorXD<X>::MatrixMxN(double k)
  9. {
  10. this->fill(k);
  11. }
  12. tmplx VectorXD<X>::MatrixMxN(const double scalars[X])
  13. {
  14. this->fill(scalars);
  15. }
  16. tmplx 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. tmpl T& GenericVector<X, T>::setScalar(unsigned i, double value)
  23. {
  24. return setScalar(i, 0,value);
  25. }
  26. tmpl double GenericVector<X, T>::getScalar(unsigned i) const
  27. {
  28. return getScalar(i, 0);
  29. }
  30. tmpl double GenericVector<X, T>::operator[](unsigned i) const
  31. {
  32. return getScalar(i);
  33. }
  34. tmpl 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. tmpl 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. tmpl T GenericVector<X, T>::crossProduct(const T &v1, const T &v2)
  53. {
  54. return T(v1).crossProduct(v2);
  55. }
  56. tmpl 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. tmpl T* GenericVector<X, T>::getThis() const
  65. {
  66. return (T*)this;
  67. }
  68. //tmpl QDebug operator<<(QDebug dbg, const T &v)
  69. //{
  70. // return dbg.nospace() << "(" << v.getX() << ", " << v.getY() << ", " << v.getZ() << ")";
  71. //}