ningshuxia
2024-04-28 cc3788df309c28a19f61331a5ec5379717799a9b
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
namespace IStation.Curve
{
    /// <summary>
    /// 装置曲线
    /// </summary>
    public class DeviceCurve : ICloneable
    {
        /// <summary>
        /// 
        /// </summary>
        public DeviceCurve() { }
 
        /// <summary>
        /// 
        /// </summary>
        public DeviceCurve(DeviceCurve rhs)
        {
            this.SourceType = rhs.SourceType;
            this.OriginPoints = rhs.OriginPoints;
            this.CurveInfo = rhs.CurveInfo;
            this.CurveExpress = rhs.CurveExpress;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public DeviceCurve(double zeroPointH, IStation.Curve.CurvePoint endPoint, int fitPointNum = 12, eFitType fitType = eFitType.CubicCurve)
        {
            SetParabolaPoints(zeroPointH, endPoint);
            ResetCurveInfo(fitPointNum, fitType);
        }
 
 
 
        /// <summary>
        /// 来源类型
        /// </summary>
        public eDeviceSourceType SourceType { get; set; }
 
        /// <summary>
        /// 手动输入时是输入的点,二次曲线是两个定义点
        /// </summary>
        public List<CurvePoint> OriginPoints { get; set; }
 
        /// <summary>
        /// 曲线上的点有可能根据坐标最小值,进行了切割
        /// </summary>
        public List<CurvePoint> CurveInfo { get; set; }
 
        /// <summary>
        /// 曲线方程
        /// </summary>
        public CurveExpress CurveExpress { get; set; }
 
        /// <summary>
        /// 获取0流量点扬程
        /// </summary>
        public double GetZeroPointH()
        {
            if (this.OriginPoints == null || this.OriginPoints.Count < 1)
            {
                return default;
            }
            return this.OriginPoints[0].Y;
        }
 
        /// <summary>
        /// 设置抛物线点
        /// </summary>
        public void SetParabolaPoints(double zeroPointH, IStation.Curve.CurvePoint endPoint)
        {
            this.SourceType = eDeviceSourceType.Twice;
            this.OriginPoints = new List<IStation.Curve.CurvePoint>();
            this.OriginPoints.Add(new IStation.Curve.CurvePoint(0, zeroPointH));
            this.OriginPoints.Add(endPoint);
        }
 
        /// <summary>
        /// 重置曲线信息
        /// </summary>
        public void ResetCurveInfo(int fitPointNum, eFitType fitType = eFitType.CubicCurve)
        {
            if (this.SourceType != eDeviceSourceType.Twice)
                return;
            if (this.OriginPoints == null || this.OriginPoints.Count != 2)
                return;
 
            double equipCurveZeroH = this.OriginPoints[0].Y;
            var endPt = this.OriginPoints[1];
            var points = new List<IStation.Curve.CurvePoint>();
            double k = (endPt.Y - equipCurveZeroH) / (endPt.X * endPt.X);
            double minQ = 0;
            double maxQ = endPt.X;
            double space = (maxQ - minQ) / (fitPointNum - 1);//11个点
            for (int i = 0; i < fitPointNum; i++)
            {
                double x = space * i + minQ;
                double y = k * x * x + equipCurveZeroH;
                points.Add(new IStation.Curve.CurvePoint(x, y));
            }
 
            this.CurveInfo = points;
            this.CurveExpress = IStation.Curve.FitHelper.BuildCurveExpress(points, fitType);
        }
 
        /// <summary>
        /// 获取抛物线系数
        /// </summary>
        public double GetParabolaCoeff()
        {
            if (this.OriginPoints == null || this.OriginPoints.Count != 2)
                return default;
 
            double equipCurveZeroH = OriginPoints[0].Y;
            var endPt = OriginPoints[1];
            List<IStation.Curve.CurvePoint> points = new List<IStation.Curve.CurvePoint>();
            return (endPt.Y - equipCurveZeroH) / (endPt.X * endPt.X);
        }
 
        /// <summary>
        /// 通过 最小值Y重置曲线信息
        /// </summary>
        public void ResetCurveInfoByMinY(int fitPointNum, double minY, eFitType fitType = eFitType.CubicCurve)
        {
            if (this.SourceType != eDeviceSourceType.Twice)
                return;
            if (this.OriginPoints == null || this.OriginPoints.Count != 2)
                return;
            if (minY < 0.01)
            {
                ResetCurveInfo(fitPointNum, fitType);
                return;
            }
 
 
            double equipCurveZeroH = this.OriginPoints[0].Y;
            var endPt = this.OriginPoints[1];
            var points = new List<IStation.Curve.CurvePoint>();
            double k = (endPt.Y - equipCurveZeroH) / (endPt.X * endPt.X);
            double minQ = 0;
            if (minY > equipCurveZeroH)
            {
                minQ = Math.Sqrt((minY - equipCurveZeroH) / k);
            }
            double maxQ = endPt.X;
            double space = (maxQ - minQ) / (fitPointNum - 1);
            for (int i = 0; i < fitPointNum; i++)
            {
                double x = space * i + minQ;
                double y = k * x * x + equipCurveZeroH;
                points.Add(new IStation.Curve.CurvePoint(x, y));
            }
 
            this.CurveInfo = points;
        }
 
 
        #region Clone
 
        /// <summary>
        /// 
        /// </summary>
        public DeviceCurve Clone()
        {
            return new DeviceCurve(this);
        }
 
        /// <summary>
        /// 
        /// </summary>
        object ICloneable.Clone()
        {
            return Clone();
        }
 
 
        #endregion
    }
}