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;
|
}
|
|
|
|
|
|
}
|
}
|