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.

104 lines
3.5 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. \documentclass[a4paper]{article}
  2. \usepackage[english]{babel}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage[fleqn]{amsmath}
  5. \usepackage{hyperref}
  6. \begin{document}
  7. \section{Math stuff}
  8. Cubic interpolation for one segment $[x_k, x_{k+1}]$ can be described as:
  9. \begin{equation*}
  10. \begin{aligned}
  11. f(t) &= c_{oef1}t^3 + c_{oef2}t^2 + c_{oef3}t + c_{oef4} \hspace{1cm} with \\
  12. t(x) &= \frac{x - x_k}{x_{k+1} - x_k}
  13. \end{aligned}
  14. \end{equation*}
  15. \hspace{1cm} and
  16. \begin{equation*}
  17. \begin{aligned}
  18. c_{oef1} &= 2p_0 - 2p_1 - m_0 - m_1 \\
  19. c_{oef2} &= -3p_0 + 3p_1 - 2m_0 - m_1 \\
  20. c_{oef3} &= m_0 \\
  21. c_{oef4} &= p_0
  22. \end{aligned}
  23. \end{equation*}
  24. (see Wikipedia-Links below)\\
  25. \\
  26. If we rewrite this as function of $d = x - x_k$ we get
  27. \begin{equation*}
  28. \begin{aligned}
  29. f'(d) &= c_{oef1}' d^3 + c_{oef2}' d^2 + c_{oef3}' d + c_{oef4}' \hspace{1cm} with \\
  30. c_{oef1}' &= \frac{c_{oef1}}{(x_{k+1} - x_k)^3} \\
  31. c_{oef2}' &= \frac{c_{oef2}}{(x_{k+1} - x_k)^2} \\
  32. c_{oef3}' &= \frac{c_{oef3}}{x_{k+1} - x_k} \\
  33. c_{oef4}' &= c_{oef4}
  34. \end{aligned}
  35. \end{equation*}
  36. \\
  37. The implemented algorithm uses two helper variables to calculate the coefficients of $f'$ efficiently:
  38. \begin{equation*}
  39. \begin{aligned}
  40. common = m_k + m_{k+1} - 2 \frac{p_{k+1} - p_k}{x_{k+1} - x_k} \\
  41. invLength = \frac{1}{x_{k+1} - x_k}
  42. \end{aligned}
  43. \end{equation*}
  44. \\
  45. We use $p_0 = p_k$, $p_1 = p_{k+1}$, $m_0 = m_k (x_{k+1} - x_k)$, $m_1 = m_{k+1} (x_{k+1} - x_k)$ and $s = \frac{p_{k+1}-p_k}{x_{k+1}-x_k}$. The tangents are scaled with the length of the segment. \\
  46. \\
  47. If we insert this into the equations for the coefficients we get the formulas that are used in the algorithm:
  48. \begin{equation*}
  49. \begin{aligned}
  50. c_{oef1}' &= \frac{c_{oef1}}{(x_{k+1} - x_k)^3} \\
  51. &= \frac{2p_0 - 2p_1 + m_0 + m_1}{(x_{k+1} - x_k)^3}\\
  52. &= (2p_k - 2p_{k+1} + m_k (x_{k+1} - x_k) + m_{k+1} (x_{k+1} - x_k) / (x_{k+1} - x_k)^3 \\
  53. &= \frac {(2p_k - 2p_{k+1} + m_k (x_{k+1} - x_k) + m_{k+1} (x_{k+1} - x_k)}{x_{k+1} - x_k} / (x_{k+1} - x_k)^2 \\
  54. &= (\frac {2p_k - 2p_{k+1}}{x_{k+1} - x_k} + m_k + m_{k+1} ) * invLength^2 \\
  55. &= (-2\frac {p_{k+1}- p_k}{x_{k+1} - x_k} + m_k + m_{k+1} ) * invLength^2 \\
  56. &= common * invLenght^2
  57. \end{aligned}
  58. \end{equation*}
  59. \begin{equation*}
  60. \begin{aligned}
  61. c_{oef2}' &= \frac{c_{oef2}}{(x_{k+1} - x_k)^2} \\
  62. &= (-3p_0 + 3p_1 - 2m_0 - m_1) / (x_{k+1} - x_k)^2 \\
  63. &= (-3p_k + 3p_{k+1} - 2* m_k (x_{k+1} - x_k) - m_{k+1} (x_{k+1} - x_k)) / (x_{k+1} - x_k)^2 \\
  64. &= (\frac{-3p_k + 3p_{k+1}}{x_{k+1} - x_k} - 2m_k - m_{k+1}) * invLenght \\
  65. &= (3\frac{p_{k+1} - p_k}{x_{k+1} - x_k} - 2m_k - m_{k+1}) * invLenght \\
  66. &=(\frac{p_{k+1} - p_k}{x_{k+1} - x_k} + 2\frac{p_{k+1} - p_k}{x_{k+1} - x_k} - m_k - m_{k+1} - m_k) * invLenght \\
  67. &= (s - common - m_k) * invLenght
  68. \end{aligned}
  69. \end{equation*}
  70. \begin{equation*}
  71. \begin{aligned}
  72. c_{oef3}' &= \frac{c_{oef3}}{x_{k+1} - x_k} \\
  73. &= \frac{m_0}{x_{k+1} - x_k} \\
  74. &= \frac{m_k (x_{k+1} - x_k)}{x_{k+1} - x_k} \\
  75. &= m_k
  76. \end{aligned}
  77. \end{equation*}
  78. \begin{equation*}
  79. \begin{aligned}
  80. c_{oef4}' &= c_{oef4} = p_0 = p_k
  81. \end{aligned}
  82. \end{equation*}
  83. \section{Useful Links}
  84. \url{http://de.wikipedia.org/w/index.php?title=Kubisch_Hermitescher_Spline&oldid=130168003)}\\
  85. \url{http://en.wikipedia.org/w/index.php?title=Monotone_cubic_interpolation&oldid=622341725}\\
  86. \url{http://math.stackexchange.com/questions/45218/implementation-of-monotone-cubic-interpolation}\\
  87. \url{http://math.stackexchange.com/questions/4082/equation-of-a-curve-given-3-points-and-additional-constant-requirements#4104}
  88. \end{document}