NonlinearPeriodicFunc.cs 1015 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Island.StandardLib.Math
  6. {
  7. /// <summary>
  8. /// 提供一个参数化的非线性周期函数拟合
  9. /// </summary>
  10. public class NonlinearPeriodicFunc
  11. {
  12. const double PI2 = 6.2831853071795862;
  13. /// <summary>
  14. /// 最低值 (x=周期点)
  15. /// </summary>
  16. public float Low { get; set; }
  17. /// <summary>
  18. /// 最高值 (x=周期中点)
  19. /// </summary>
  20. public float High { get; set; }
  21. /// <summary>
  22. /// 周期长度
  23. /// </summary>
  24. public float Length { get; set; }
  25. public NonlinearPeriodicFunc(float low, float high, float length)
  26. {
  27. Low = low;
  28. High = high;
  29. Length = length;
  30. }
  31. public float f(float inputx)
  32. {
  33. return (float)(-System.Math.Cos(PI2 * inputx / Length) + 1) * ((High - Low) * 0.5f) + Low;
  34. }
  35. }
  36. }