lixiaojun
2023-11-02 cee1c6bf2c5c03c0beadcc9c8f720b03589f83a3
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
namespace Yw.Curve
{
    /// <summary>
    /// 曲线拟合辅助类
    /// </summary>
    public class FitHelper
    {
        /// <summary>
        /// 
        /// </summary>
        public FitHelper(CurveExpress express)
        {
            switch (express.FitType)
            {
                case eFitType.ThroughPoint: _fitPoint = new TwinRelateCurve0(express); break;
                case eFitType.LinearCurve: _fitPoint = new TwinRelateCurve1(express); break;
                case eFitType.ConicCurveB0: _fitPoint = new TwinRelateCurve2B0(express); break;
                case eFitType.ConicCurve: _fitPoint = new TwinRelateCurve2M(express); break;
                case eFitType.CubicCurve: _fitPoint = new TwinRelateCurve3M(express); break;
                case eFitType.FourM: _fitPoint = new TwinRelateCurve4M(express); break;
                default: break;
            }
        }
 
        /// <summary>
        /// 
        /// </summary>
        public FitHelper(List<CurvePoint> points, eFitType fitType = eFitType.CubicCurve)
        {
            switch (fitType)
            {
                case eFitType.ThroughPoint: _fitPoint = new TwinRelateCurve0(points); break;
                case eFitType.LinearCurve: _fitPoint = new TwinRelateCurve1(points); break;
                case eFitType.ConicCurveB0: _fitPoint = new TwinRelateCurve2B0(points); break;
                case eFitType.ConicCurve: _fitPoint = new TwinRelateCurve2M(points); break;
                case eFitType.CubicCurve: _fitPoint = new TwinRelateCurve3M(points); break;
                case eFitType.FourM: _fitPoint = new TwinRelateCurve4M(points); break;
                default: break;
            }
        }
 
 
        //拟合接口对象
        private IFitPoint _fitPoint = null;
 
        /// <summary>
        /// 获取曲线拟合点Y值
        /// </summary>
        public double GetFitPointY(double x)
        {
            if (_fitPoint == null)
                return default;
            return _fitPoint.GetFitPointY(x);
        }
 
        /// <summary>
        /// 获取拟合点列表
        /// </summary>
        public List<CurvePoint> GetFitPoints(int pointNumber)
        {
            if (_fitPoint == null)
                return default;
            return _fitPoint.GetFitPoints(pointNumber);
        }
 
        /// <summary>
        /// 通过X区间获取拟合点列表
        /// </summary>
        public List<CurvePoint> GetFitPointsByXRange(double minX, double maxX, int pointNumber)
        {
            if (_fitPoint == null)
                return default;
            return _fitPoint.GetFitPointsByXRange(minX, maxX, pointNumber);
        }
 
        /// <summary>
        /// 获取拟合点Y
        /// </summary>
        public static double GetFitPointY(CurveExpress express, double x)
        {
            if (express == null)
                return default;
            var helper = new FitHelper(express);
            return helper.GetFitPointY(x);
        }
 
        /// <summary>
        /// 获取拟合点
        /// </summary>
        public static List<CurvePoint> GetFitPoints(CurveExpress express, int pointNumber)
        {
            if (express == null)
                return default;
            var helper = new FitHelper(express);
            return helper.GetFitPoints(pointNumber);
        }
 
        /// <summary>
        /// 获取拟合点
        /// </summary>
        public static List<CurvePoint> GetFitPointsByXRange(CurveExpress express, double minX, double maxX, int pointNumber)
        {
            if (express == null)
                return default;
            var helper = new FitHelper(express);
            return helper.GetFitPointsByXRange(minX, maxX, pointNumber);
        }
 
        /// <summary>
        /// 获取拟合次方
        /// </summary>
        public static int GetFitPow(eFitType fitType)
        {
            switch (fitType)
            {
                case eFitType.CubicCurve: return 3;
                case eFitType.ConicCurve: return 2;
                case eFitType.ConicCurveB0: return 2;
                case eFitType.LinearCurve: return 1;
                case eFitType.ThroughPoint: return 0;
                case eFitType.FourM: return 4;
                default: return 3;
            }
        }
 
        /// <summary>
        /// 获取拟合类型
        /// </summary>
        public static eFitType GetFitType(int fitPow)
        {
            switch (fitPow)
            {
                case 3: return eFitType.CubicCurve;
                case 2: return eFitType.ConicCurve;
                case 1: return eFitType.LinearCurve;
                case 0: return eFitType.ThroughPoint;
                case 4: return eFitType.FourM;
                default: return eFitType.CubicCurve;
            }
        }
 
        /// <summary>
        /// 创建曲线表达式
        /// </summary>
        public static CurveExpress BuildCurveExpress(List<CurvePoint> points, eFitType fitType)
        {
            if (points == null || !points.Any())
            {
                return default;
            }
            switch (fitType)
            {
                case eFitType.ThroughPoint: return TwinRelateCurve0.BuildCurveExpress(points);
                case eFitType.LinearCurve: return TwinRelateCurve1.BuildCurveExpress(points);
                case eFitType.ConicCurveB0: return TwinRelateCurve2B0.BuildCurveExpress(points);
                case eFitType.ConicCurve: return TwinRelateCurve2M.BuildCurveExpress(points);
                case eFitType.CubicCurve: return TwinRelateCurve3M.BuildCurveExpress(points);
                case eFitType.FourM: return TwinRelateCurve4M.BuildCurveExpress(points);
                default: return default;
            }
        }
 
    }
}