duheng
2025-02-19 ad8f813f5eddd66740b4e09801e4ea02ddf70a4a
WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/00-core/Point3d.cs
@@ -90,5 +90,76 @@
            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);
        }
    }
}