ningshuxia
2024-05-24 7a89858cd237c4fc5d0c952804d35fcaa62be57d
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
namespace IStation.Curve
{
    /// <summary>
    /// 曲线点
    /// </summary>
    public partial class CurvePoint : JsonList<CurvePoint>, ICloneable
    {
 
        /// <summary>
        /// 
        /// </summary>
        public CurvePoint() { }
 
        /// <summary>
        /// 
        /// </summary>
        public CurvePoint(int x, int y)
        {
            this.X = x;
            this.Y = y;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public CurvePoint(float x, float y)
        {
            this.X = x;
            this.Y = y;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public CurvePoint(double x, double y)
        {
            this.X = x;
            this.Y = y;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public CurvePoint(decimal x, decimal y)
        {
            this.X = (double)x;
            this.Y = (double)y;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public CurvePoint(CurvePoint rhs)
        {
            this.X = rhs.X;
            this.Y = rhs.Y;
        }
 
 
        /// <summary>
        /// X
        /// </summary>
        public double X { get; set; }
 
        /// <summary>
        /// Y
        /// </summary>
        public double Y { get; set; }
 
        /// <summary>
        ///  获取两点之间的距离
        /// </summary>
        public double Distance(CurvePoint pt)
        {
            if (pt == null)
            {
                return double.MaxValue;
            }
            return Math.Sqrt(Math.Pow(this.X - pt.X, 2) + Math.Pow(this.Y - pt.Y, 2));
        }
 
        /// <summary>
        /// 获取点到线的距离
        /// </summary>
        public double Distance(List<CurvePoint> ptList)
        {
            if (ptList == null || ptList.Count < 1)
            {
                return double.MaxValue;
            }
            return ptList.Min(x => x.Distance(this));
        }
 
        /// <summary>
        /// 判断是否是零点
        /// </summary>
        public bool IsZeroPoint()
        {
            if (this.X < 0.01 && this.Y < 0.01)
            {
                return true;
            }
            return false;
        }
 
        /*/// <summary>
        /// 判断是否为有效点
        /// </summary>
        public bool IsValidPoint()
        {
            if (!(!double.IsNormal(this.X) || !double.IsNormal(this.Y)))
            {
                return true;
            }
            return false;
        }*/
 
        /// <summary>
        /// 判断是否为无效点
        /// </summary>
        public bool IsInvalidPoint()
        {
            if (double.IsNaN(this.X) || double.IsInfinity(this.X) || this.X == double.MinValue || this.X == double.MaxValue)
            {
                return true;
            }
            if (double.IsNaN(this.Y) || double.IsInfinity(this.Y) || this.Y == double.MinValue || this.Y == double.MaxValue)
            {
                return true;
            }
            return false;
        }
 
        /// <summary>
        /// 是否沿x轴的射线穿透线段,有交点且在线的左边
        /// </summary>
        public bool IsIntersectLineLeft(CurvePoint pt1, CurvePoint pt2)
        {
            if (pt1 == null || pt2 == null)
            {
                return false;
            }
            if (Math.Abs(pt1.Y - pt2.Y) < 0.0001)
            {
                if (Math.Abs(this.Y - pt1.Y) < 0.0001)
                {
                    return true;
                }
            }
            var ymin = UtilsHelper.Min(pt1.Y, pt2.Y);
            var ymax = UtilsHelper.Max(pt1.Y, pt2.Y);
            if (this.Y < ymax && this.Y >= ymin)
            {
                if (this.X <= (pt1.X + (pt2.X - pt1.X) * (this.Y - pt1.Y) / (pt2.Y - pt1.Y)))
                {
                    return true;
                }
            }
            return false;
        }
 
 
        /// <summary>
        /// 
        /// </summary>
        public CurvePoint Clone()
        {
            return new CurvePoint(this);
        }
 
        /// <summary>
        /// 
        /// </summary>
        object ICloneable.Clone()
        {
            return this.Clone();
        }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    }
 
 
 
 
}