PolynomialCurve.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // David Eberly, Geometric Tools, Redmond WA 98052
  2. // Copyright (c) 1998-2020
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // https://www.boost.org/LICENSE_1_0.txt
  5. // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
  6. // Version: 4.0.2019.08.13
  7. #pragma once
  8. #include <Mathematics/ParametricCurve.h>
  9. #include <Mathematics/Polynomial1.h>
  10. namespace WwiseGTE
  11. {
  12. template <int N, typename Real>
  13. class PolynomialCurve : public ParametricCurve<N, Real>
  14. {
  15. public:
  16. // Construction and destruction. The default constructor creates a
  17. // polynomial curve with all components set to the constant zero (all
  18. // degree-0 polynomials). You can set these to other polynomials
  19. // using member accessors.
  20. PolynomialCurve(Real tmin, Real tmax)
  21. :
  22. ParametricCurve<N, Real>(tmin, tmax)
  23. {
  24. }
  25. PolynomialCurve(Real tmin, Real tmax,
  26. std::array<Polynomial1<Real>, N> const& components)
  27. :
  28. ParametricCurve<N, Real>(tmin, tmax)
  29. {
  30. for (int i = 0; i < N; ++i)
  31. {
  32. SetPolynomial(i, components[i]);
  33. }
  34. }
  35. virtual ~PolynomialCurve()
  36. {
  37. }
  38. // Member access.
  39. void SetPolynomial(int i, Polynomial1<Real> const& poly)
  40. {
  41. mPolynomial[i] = poly;
  42. mDer1Polynomial[i] = mPolynomial[i].GetDerivative();
  43. mDer2Polynomial[i] = mDer1Polynomial[i].GetDerivative();
  44. mDer3Polynomial[i] = mDer2Polynomial[i].GetDerivative();
  45. }
  46. inline Polynomial1<Real> const& GetPolynomial(int i) const
  47. {
  48. return mPolynomial[i];
  49. }
  50. inline Polynomial1<Real> const& GetDer1Polynomial(int i) const
  51. {
  52. return mDer1Polynomial[i];
  53. }
  54. inline Polynomial1<Real> const& GetDer2Polynomial(int i) const
  55. {
  56. return mDer2Polynomial[i];
  57. }
  58. inline Polynomial1<Real> const& GetDer3Polynomial(int i) const
  59. {
  60. return mDer3Polynomial[i];
  61. }
  62. // Evaluation of the curve. The function supports derivative
  63. // calculation through order 3; that is, order <= 3 is required. If
  64. // you want/ only the position, pass in order of 0. If you want the
  65. // position and first derivative, pass in order of 1, and so on. The
  66. // output array 'jet' must have enough storage to support the maximum
  67. // order. The values are ordered as: position, first derivative,
  68. // second derivative, third derivative.
  69. virtual void Evaluate(Real t, unsigned int order, Vector<N, Real>* jet) const override
  70. {
  71. for (int i = 0; i < N; ++i)
  72. {
  73. jet[0][i] = mPolynomial[i](t);
  74. }
  75. if (order >= 1)
  76. {
  77. for (int i = 0; i < N; ++i)
  78. {
  79. jet[1][i] = mDer1Polynomial[i](t);
  80. }
  81. if (order >= 2)
  82. {
  83. for (int i = 0; i < N; ++i)
  84. {
  85. jet[2][i] = mDer2Polynomial[i](t);
  86. }
  87. if (order == 3)
  88. {
  89. for (int i = 0; i < N; ++i)
  90. {
  91. jet[3][i] = mDer3Polynomial[i](t);
  92. }
  93. }
  94. }
  95. }
  96. }
  97. protected:
  98. std::array<Polynomial1<Real>, N> mPolynomial;
  99. std::array<Polynomial1<Real>, N> mDer1Polynomial;
  100. std::array<Polynomial1<Real>, N> mDer2Polynomial;
  101. std::array<Polynomial1<Real>, N> mDer3Polynomial;
  102. };
  103. }