Shuxia Ning
2025-01-03 5e776f1884d4d865c8d3d037a1fb10fb083f37ed
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
namespace Yw.WinFrmUI.Phart
{
    public static class Point2dListExtensions
    {
 
        /// <summary>
        ///  是否完全相同
        /// </summary> 
        public static bool IsEqualValueX(this List<Yw.Geometry.Point2d> pt_list, List<Yw.Geometry.Point2d> comparer_pt_list)
        {
            if (pt_list == null || pt_list.Count() == 0)
            {
                if (comparer_pt_list == null || comparer_pt_list.Count() == 0)
                {
                    return true;
                }
 
                return false;
            }
 
            if (comparer_pt_list == null || comparer_pt_list.Count() == 0)
            {
                if (pt_list == null || pt_list.Count() == 0)
                {
                    return true;
                }
 
                return false;
            }
 
            if (pt_list.Count != comparer_pt_list.Count)
            {
                return false;
            }
 
            for (int i = 0; i < pt_list.Count; i++)
            {
                if (Math.Abs(pt_list[i].X - comparer_pt_list[i].X) > 0.001)
                {
                    return false;
                }
            }
 
            return true;
        }
 
 
        /// <summary>
        /// 修改曲线0点位置的值,曲线值会根据比例逐渐变化,直到fixPtX,不再变化
        /// </summary> 
        public static List<Yw.Geometry.Point2d> AmendByZeroPointY(this List<Yw.Geometry.Point2d> pt_list, double fix_point_x, double zero_point_y,Yw.Ahart.eFeatType feat_type= Ahart.eFeatType.Cubic)
        {
            if (pt_list == null || pt_list.Count < 3)
                return null;
 
            var fit_pt_list = new List<Yw.Geometry.Point2d>();
 
            //计算差距
            double zeroDis = pt_list.First().Y - zero_point_y;
            for (int i = 0; i < pt_list.Count; i++)
            {
                double dis = 0;
                if (pt_list[i].X <= fix_point_x)
                {
                    dis = zeroDis * (1 - pt_list[i].X / fix_point_x);
                }
                else
                {
                    dis = 0;
                }
 
                fit_pt_list.Add(new Yw.Geometry.Point2d(pt_list[i].X, pt_list[i].Y - dis));
            }
            var new_pt_list = new List<Yw.Geometry.Point2d>();
            switch (feat_type)
            {
                case Ahart.eFeatType.Polynomial:
                    {
                        new_pt_list=new Yw.Geometry.PolynomialSpline2d(fit_pt_list).GetPointList();
                    }
                    break;
                case Ahart.eFeatType.Cubic:
                    {
                        new_pt_list = new Yw.Geometry.CubicSpline2d(fit_pt_list).GetPointList();
                    }
                    break;
                case Ahart.eFeatType.Through:
                    {
                        new_pt_list = new Yw.Geometry.ThroughSpline2d(fit_pt_list).GetPointList();
                    }
                    break; 
            }
            return new_pt_list;
        }
 
 
        /// <summary>
        /// 
        /// </summary> 
        public static List<Yw.Geometry.Point2d> GetFitPointList(this List<Yw.Geometry.Point2d> pt_list)
        {
            if (pt_list == null || !pt_list.Any())
                return default;
 
            var cubic_spline = new Yw.Geometry.CubicSpline2d(pt_list);
            return cubic_spline.GetPointList(pt_list.Count);
        }
 
        /// <summary>
        /// 
        /// </summary> 
        public static List<Yw.Geometry.Point2d> GetFitPointList(this List<Yw.Geometry.Point2d> pt_list, Yw.Ahart.eFeatType feat_type, int pt_count = 30)
        {
            if (pt_list == null || !pt_list.Any())
                return default;
            switch (feat_type)
            {
                case Ahart.eFeatType.Polynomial:
                    {
                        var curve = new Yw.Geometry.PolynomialSpline2d(pt_list);
                        return curve.GetPointList(pt_count);
                    }
                case Ahart.eFeatType.Cubic:
                    {
                        if (pt_list.Count < 4)
                        {
                            return default;
                        }
                        var curve = new Yw.Geometry.CubicSpline2d(pt_list);
                        return curve.GetPointList(pt_count);
                    }
                case Ahart.eFeatType.Through:
                    {
                        var curve = new Yw.Geometry.ThroughSpline2d(pt_list);
                        return curve.GetPointList(pt_count);
                    }
            }
 
            return default;
        }
 
        /// <summary>
        /// 
        /// </summary> 
        public static string ToDbString(this List<Yw.Geometry.Point2d> pt_list, Yw.Ahart.eCurveType curve_type, Yw.Ahart.eFeatType feat_type, int pt_count = 30)
        {
            if (pt_list == null || !pt_list.Any())
                return default;
            var fit_pt_list = new List<Yw.Geometry.Point2d>();
            switch (feat_type)
            {
                case Ahart.eFeatType.Polynomial:
                    {
                        var curve = new Yw.Geometry.PolynomialSpline2d(pt_list);
                        fit_pt_list = curve.GetPointList(pt_count);
                    }
                    break;
                case Ahart.eFeatType.Cubic:
                    {
                        var curve = new Yw.Geometry.CubicSpline2d(pt_list);
                        fit_pt_list = curve.GetPointList(pt_count);
                    }
                    break;
                case Ahart.eFeatType.Through:
                    {
                        var curve = new Yw.Geometry.ThroughSpline2d(pt_list);
                        fit_pt_list = curve.GetPointList(pt_count);
                    }
                    break;
            }
 
            switch (curve_type)
            {
                case Ahart.eCurveType.QH:
                    {
                        return new Yw.Pump.CurveQH(feat_type, fit_pt_list).ToDbString();
                    } 
                case Ahart.eCurveType.QP:
                    {
                        return new Yw.Pump.CurveQP(feat_type, fit_pt_list).ToDbString();
                    }
                case Ahart.eCurveType.QE:
                    {
                        return new Yw.Pump.CurveQE(feat_type, fit_pt_list).ToDbString();
                    }
                case Ahart.eCurveType.QNPSH:
                    {
                        return default;
                    }
                case Ahart.eCurveType.EqualE:
                    {
                        return new Yw.Pump.CurveEqualE(feat_type, fit_pt_list).ToDbString();
                    }
                case Ahart.eCurveType.EqualP:
                    {
                        return new Yw.Pump.CurveEqualP(feat_type, fit_pt_list).ToDbString();
                    }
                case Ahart.eCurveType.QL:
                    {
                        return new Yw.Ahart.CurveQL(feat_type, fit_pt_list).ToDbString();
                    }
                case Ahart.eCurveType.OL:
                    {
                        return new Yw.Ahart.CurveOL(feat_type, fit_pt_list).ToDbString();
                    }
                case Ahart.eCurveType.VOL:
                    {
                        return new Yw.Ahart.CurveVOL(feat_type, fit_pt_list).ToDbString();
                    }
                default:
                    {
                        return new Yw.Pump.CurveQH(feat_type, fit_pt_list).ToDbString();
                    }
            }
        }
 
       
 
        /// <summary>
        /// 
        /// </summary> 
        public static List<Yw.Geometry.Point2d> GetExpandFitPointList(this List<Yw.Geometry.Point2d> pt_list, double expand_ratio)
        {
            if (pt_list == null || !pt_list.Any())
                return default;
 
            var cubic_spline = new Yw.Geometry.CubicSpline2d(pt_list);
            cubic_spline.MaxX = cubic_spline.MaxX * expand_ratio;
            return cubic_spline.GetPointList(pt_list.Count);
        }
 
        /// <summary>
        /// 
        /// </summary> 
        public static List<Yw.Geometry.Point2d> GetFitPointList(this List<Yw.Geometry.Point2d> pt_list, int point_count)
        {
            if (pt_list == null || !pt_list.Any())
                return default;
 
            var cubic_spline = new Yw.Geometry.CubicSpline2d(pt_list);
            return cubic_spline.GetPointList(point_count);
        }
 
        /// <summary>
        /// 计算总长度
        /// </summary>
        public static double  TotalLength(this IEnumerable<Yw.Geometry.Point2d> srcList)
        {
            if (srcList == null || srcList.Count() < 2)
                return default;
            var list = srcList.ToList();
            double length = 0;
            for (int i = 1; i < list.Count(); i++)
            {
                double len = Math.Sqrt((list[i].X - list[i - 1].X) * (list[i].X - list[i - 1].X) + (list[i].Y - list[i - 1].Y) * (list[i].Y - list[i - 1].Y));
                length += len;
            }
            return length;
        }
 
        //public static List<Yw.Geometry.Point2d> GetInterPointsX(this List<Yw.Geometry.Point2d> pt_list, double y)
        //{
        //    if (pt_list == null || pt_list.Count < 2)
        //    {
        //        return default;
        //    }
        //    var list = new List<Yw.Geometry.Point2d>();
        //    for (int i = 0; i < pt_list.Count - 1; i++)
        //    {
        //        if ((y >= pt_list[i].Y && y <= pt_list[i + 1].Y) || (y <= pt_list[i].Y && y >= pt_list[i + 1].Y))
        //        {//直线插值
        //            double x;
        //            if (Math.Abs(pt_list[i].Y - pt_list[i + 1].Y) < 0.01)
        //                x = (pt_list[i].X + pt_list[i + 1].X) * 0.5;
        //            else
        //                x = pt_list[i].X + (pt_list[i + 1].X - pt_list[i].X) * (y - pt_list[i].Y) / (pt_list[i + 1].Y - pt_list[i].Y);
 
        //            list.Add(new Yw.Geometry.Point2d(x, y));
        //        }
        //    }
        //    return list;
        //}
 
 
        /// <summary>
        /// 根据周长度计算点位置,返回空表示超过总长
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static Yw.Geometry.Point2d GetPosiByLength(this List<Yw.Geometry.Point2d> srcList,double length_from_start)
        {
            if (length_from_start < 0.0001)
                return srcList.FirstOrDefault();
            double length = 0;
            for (int i = 1; i < srcList.Count; i++)
            {
                double len_line = Math.Sqrt((srcList[i].X - srcList[i - 1].X) * (srcList[i].X - srcList[i - 1].X) + (srcList[i].Y - srcList[i - 1].Y) * (srcList[i].Y - srcList[i - 1].Y));
                length += len_line; 
                if (length >= length_from_start)
                {
                    Yw.Geometry.Point2d extPt = new Yw.Geometry.Point2d();
                    extPt.X = (srcList[i - 1].X - srcList[i].X) * (length - length_from_start) / len_line + srcList[i].X;
                    extPt.Y = (srcList[i - 1].Y - srcList[i].Y) * (length - length_from_start) / len_line + srcList[i].Y;
                    return extPt;
                }
            }
            if (length >= length_from_start * 0.9999)
            { 
                return srcList.LastOrDefault();
            }
            return null;
        }
 
        /// <summary>
        /// 获取Y最小的点的序号
        /// </summary>
        /// <returns></returns>
        public static  int GetPointIndexOfMinY(this List<Yw.Geometry.Point2d> srcList )
        {
            if (srcList.Count() == 0)
                return 0;
            if (srcList.Count() == 1)
                return 0;
            var minY = (from x in srcList select x.Y).Min();
            var pt = (from x in srcList where x.Y == minY select x).FirstOrDefault();
            if (pt == null)
                return 0;
            else
                return srcList.IndexOf(pt);
        }
    }
}