duheng
2025-03-20 bc0ed5b6cfda6c72c06f451b77da8518c41ab210
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
namespace Yw.WinFrmUI.HydroL3d
{
    /// <summary>
    /// 
    /// </summary>
    [TypeConverter(typeof(PropertySorter))]
    public class Point3d
    {
        /// <summary>
        /// 
        /// </summary>
        public Point3d() { }
 
        /// <summary>
        /// 
        /// </summary>
        public Point3d(float x, float y, float z)
        {
            this.X = x;
            this.Y = y;
            this.Z = z;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public Point3d(double x, double y, double z)
        {
            this.X = (float)x;
            this.Y = (float)y;
            this.Z = (float)z;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public Point3d(Point3d rhs)
        {
            this.X = rhs.X;
            this.Y = rhs.Y;
            this.Z = rhs.Z;
        }
 
        /// <summary>
        /// x
        /// </summary>
        [DisplayName("X")]
        [PropertyOrder(1)]
        public float X { get; set; }
 
        /// <summary>
        /// y
        /// </summary>
        [DisplayName("Y")]
        [PropertyOrder(2)]
        public float Y { get; set; }
 
        /// <summary>
        /// z
        /// </summary>
        [DisplayName("Z")]
        [PropertyOrder(3)]
        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(Point3d 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 LengthSquared()
        {
            return X * X + Y * Y + Z * Z;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public float Length()
        {
            return (float)Math.Sqrt(LengthSquared());
        }
 
        /// <summary>
        /// 
        /// </summary>
        public void Normalize()
        {
            float length = Length();
            if (length > 0)
            {
                X /= length;
                Y /= length;
                Z /= length;
            }
        }
 
        /// <summary>
        /// - 运算
        /// </summary>
        public static Point3d operator -(Point3d a, Point3d b)
        {
            return new Point3d(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
        }
 
 
        /// <summary>
        /// 
        /// </summary>
        public static float DotProduct(Point3d a, Point3d b)
        {
            return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public static Point3d CrossProduct(Point3d a, Point3d b)
        {
            return new Point3d(
                a.Y * b.Z - a.Z * b.Y,
                a.Z * b.X - a.X * b.Z,
                a.X * b.Y - a.Y * b.X);
        }
 
 
    }
}