lixiaojun
2025-03-20 5066a3d90ab19f8380dbb4159d57b0b8e3f17649
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
namespace Yw.WinFrmUI.Hydro
{
    /// <summary>
    /// 
    /// </summary>
    public class PointL3d
    {
        /// <summary>
        /// 
        /// </summary>
        public PointL3d() { }
 
        /// <summary>
        /// 
        /// </summary>
        public PointL3d(float value)
        {
            this.X = value;
            this.Y = value;
            this.Z = value;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public PointL3d(float x, float y, float z)
        {
            this.X = x;
            this.Y = y;
            this.Z = z;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public PointL3d(double value)
        {
            var fValue = (float)value;
            this.X = fValue;
            this.Y = fValue;
            this.Z = fValue;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public PointL3d(double x, double y, double z)
        {
            this.X = (float)x;
            this.Y = (float)y;
            this.Z = (float)z;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public PointL3d(PointL3d rhs)
        {
            this.X = rhs.X;
            this.Y = rhs.Y;
            this.Z = rhs.Z;
        }
 
        /// <summary>
        /// x
        /// </summary>
        public float X { get; set; }
 
        /// <summary>
        /// y
        /// </summary>
        public float Y { get; set; }
 
        /// <summary>
        /// z
        /// </summary>
        public float Z { get; set; }
 
        /// <summary>
        /// 是否无效
        /// </summary>
        public bool InValid()
        {
            if (this.X.Invalid())
            {
                return true;
            }
            if (this.Y.Invalid())
            {
                return true;
            }
            if (this.Z.Invalid())
            {
                return true;
            }
            return false;
        }
 
        /// <summary>
        /// 是否有效
        /// </summary>
        public bool Valid()
        {
            return !InValid();
        }
 
        /// <summary>
        /// 距离
        /// </summary>
        public float Distance(PointL3d other)
        {
            if (other == null)
            {
                return default;
            }
            return MathF.Sqrt(MathF.Pow(this.X - other.X, 2) + MathF.Pow(this.Y - other.Y, 2) + MathF.Pow(this.Z - other.Z, 2));
        }
 
        /// <summary>
        /// 长度
        /// </summary>
        public float Length => MathF.Sqrt(X * X + Y * Y + Z * Z);
 
        /// <summary>
        /// 缩放到单位长度
        /// </summary>
        public void Normalize()
        {
            var length = Length;
            if (length > 0)
            {
                float num = 1f / Length;
                X *= num;
                Y *= num;
                Z *= num;
            }
        }
 
        /// <summary>
        /// 缩放到单位长度
        /// </summary>
        public PointL3d Normalized()
        {
            var result = this;
            result.Normalize();
            return result;
        }
 
 
        /// <summary>
        /// - 运算
        /// </summary>
        public static PointL3d operator -(PointL3d a, PointL3d b)
        {
            return new PointL3d(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
        }
 
        /// <summary>
        /// +运算
        /// </summary>
        public static PointL3d operator +(PointL3d a, PointL3d b)
        {
            return new PointL3d(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
        }
 
 
        /// <summary>
        /// 
        /// </summary>
        public static float DotProduct(PointL3d a, PointL3d b)
        {
            return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public static PointL3d CrossProduct(PointL3d a, PointL3d b)
        {
            return new PointL3d(
                a.Y * b.Z - a.Z * b.Y,
                a.Z * b.X - a.X * b.Z,
                a.X * b.Y - a.Y * b.X);
        }
 
        /// <summary>
        /// 返回从相应分量中的最小值创建的向量
        /// </summary>
        public static PointL3d ComponentMin(PointL3d a, PointL3d b)
        {
            a.X = ((a.X < b.X) ? a.X : b.X);
            a.Y = ((a.Y < b.Y) ? a.Y : b.Y);
            a.Z = ((a.Z < b.Z) ? a.Z : b.Z);
            return a;
        }
 
        /// <summary>
        /// 返回从相应分量中最大的一个创建的向量
        /// </summary>
        public static PointL3d ComponentMax(PointL3d a, PointL3d b)
        {
            a.X = ((a.X > b.X) ? a.X : b.X);
            a.Y = ((a.Y > b.Y) ? a.Y : b.Y);
            a.Z = ((a.Z > b.Z) ? a.Z : b.Z);
            return a;
        }
 
 
 
 
 
    }
}