ningshuxia
2022-11-14 e4680615a852b2eb115b32c8bcbc3b788c3f9ef4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.Model
{
    /// <summary>
    /// 不拟合
    /// </summary>
    public class TwinRelateCurve0 : IFitCurvePoint
    {
        public TwinRelateCurve0(CurveExpress express)
        {
            _express = express;
        }
        public TwinRelateCurve0(List<Model.CurvePoint> points)
        {
            if (points == null || points.Count < 4)
            {
                throw new Exception("出现数值计算问题, 无法解出不拟合线!");
            }
            _express = BuildCurveExpress(points);
        }
 
        private CurveExpress _express = null;
 
        /// <summary>
        /// 创建曲线表达式
        /// </summary>
        public static CurveExpress BuildCurveExpress(List<CurvePoint> points)
        {
            if (points == null || points.Count < 4)
            {
                return default;
            }
            points = points.OrderBy(x => x.X).ToList();
            var express = new CurveExpress();
            express.FitPow = 0;
            express.FitType = eCurveFitType.ThroughPoint;
            express.DefinePoints = points.Select(x => new CurvePoint(x)).ToList();
            var xxx = from x in points select x.X;
            express.Min = xxx.Min();
            express.Max = xxx.Max();
            return express;
        }
 
        /// <summary>
        /// 获取拟合点Y
        /// </summary>
        public double GetFitPointY(double x)
        {
            if (_express == null)
                return default;
            //尽量用贝塞尔曲线
            if (_express.DefinePoints != null && _express.DefinePoints.Count > 4)
            {
                var b = BezierCurveHelper.CreateOpenCurves(_express.DefinePoints);
                var s = BezierCurveHelper.GetSectPointsByX(b, x);
                if (s != null&&s.Count>0)
                {
                    return s.Last().Y;
                }
            }
 
            if (_express.DefinePoints != null && _express.DefinePoints.Count > 1)
            {
                var sect = _express.DefinePoints.GetInterPointY(x);
                if (sect == null || sect.Count < 1)
                    return default;
                return sect.First();
            }
            return default;
        }
 
        /// <summary>
        /// 获取拟合点列表
        /// </summary>
        public List<CurvePoint> GetFitPoints(int pointNumber)
        {
            if (_express == null)
                return default;
            return _express.DefinePoints;
        }
 
        /// <summary>
        /// 通过区间获取拟合点列表
        /// </summary>
        public List<CurvePoint> GetFitPointsByRange(double x_min, double x_max, int pointNumber)
        {
            if (_express == null)
                return default;
            return _express.DefinePoints;
        }
 
    }
}