LinearInterpolation.cs 698 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace DW5S.App
  7. {
  8. public class LinearInterpolation
  9. {
  10. public static double CalSigTimeDto(DateTime x, DateTime x0, DateTime x1, double y0, double y1)
  11. {
  12. // 线性插值公式: y = y0 + (x - x0) * ((y1 - y0) / (x1 - x0))
  13. if (x0 == x1)
  14. {
  15. return (y0 + y1) / 2;
  16. }
  17. double y = y0 + (x - x0).TotalSeconds * ((y1 - y0) / (x1 - x0).TotalSeconds);
  18. if (y == double.NaN)
  19. {
  20. y = 0;
  21. }
  22. return Math.Round(y, 3);
  23. }
  24. }
  25. }