| | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | [TypeConverter(typeof(PropertySorter))] |
| | | public class Point3d |
| | | { |
| | | /// <summary> |
| | |
| | | } |
| | | |
| | | /// <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> |
| | |
| | | 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); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |