CubicSpline.h 870 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include "Common.h"
  3. #include "Point.h"
  4. #include <vector>
  5. NS_BF_BEGIN;
  6. class CubicVal
  7. {
  8. public:
  9. float a,b,c,d; /* a + b*u + c*u^2 +d*u^3 */
  10. public:
  11. CubicVal(float a = 0, float b = 0, float c = 0, float d = 0)
  12. {
  13. this->a = a;
  14. this->b = b;
  15. this->c = c;
  16. this->d = d;
  17. }
  18. void Set(float a, float b, float c, float d)
  19. {
  20. this->a = a;
  21. this->b = b;
  22. this->c = c;
  23. this->d = d;
  24. }
  25. /** evaluate cubic */
  26. float Evaluate(float u)
  27. {
  28. return (((d*u) + c)*u + b)*u + a;
  29. }
  30. };
  31. class CubicSpline2D
  32. {
  33. public:
  34. std::vector<PointF> mInputPoints;
  35. CubicVal* mXCubicArray;
  36. CubicVal* mYCubicArray;
  37. public:
  38. CubicVal* SolveCubic(std::vector<float> vals);
  39. public:
  40. CubicSpline2D();
  41. ~CubicSpline2D();
  42. void AddPt(float x, float y);
  43. int GetLength();
  44. void Calculate();
  45. PointF Evaluate(float t);
  46. };
  47. NS_BF_END;