namespace IStation.Curve
|
{
|
/// <summary>
|
/// 曲线点
|
/// </summary>
|
public partial class CurvePoint : JsonList<CurvePoint>, ICloneable
|
{
|
|
/// <summary>
|
///
|
/// </summary>
|
public CurvePoint() { }
|
|
/// <summary>
|
///
|
/// </summary>
|
public CurvePoint(int x, int y)
|
{
|
this.X = x;
|
this.Y = y;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public CurvePoint(float x, float y)
|
{
|
this.X = x;
|
this.Y = y;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public CurvePoint(double x, double y)
|
{
|
this.X = x;
|
this.Y = y;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public CurvePoint(decimal x, decimal y)
|
{
|
this.X = (double)x;
|
this.Y = (double)y;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public CurvePoint(CurvePoint rhs)
|
{
|
this.X = rhs.X;
|
this.Y = rhs.Y;
|
}
|
|
|
/// <summary>
|
/// X
|
/// </summary>
|
public double X { get; set; }
|
|
/// <summary>
|
/// Y
|
/// </summary>
|
public double Y { get; set; }
|
|
/// <summary>
|
/// 获取两点之间的距离
|
/// </summary>
|
public double Distance(CurvePoint pt)
|
{
|
if (pt == null)
|
{
|
return double.MaxValue;
|
}
|
return Math.Sqrt(Math.Pow(this.X - pt.X, 2) + Math.Pow(this.Y - pt.Y, 2));
|
}
|
|
/// <summary>
|
/// 获取点到线的距离
|
/// </summary>
|
public double Distance(List<CurvePoint> ptList)
|
{
|
if (ptList == null || ptList.Count < 1)
|
{
|
return double.MaxValue;
|
}
|
return ptList.Min(x => x.Distance(this));
|
}
|
|
/// <summary>
|
/// 判断是否是零点
|
/// </summary>
|
public bool IsZeroPoint()
|
{
|
if (this.X < 0.01 && this.Y < 0.01)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
/*/// <summary>
|
/// 判断是否为有效点
|
/// </summary>
|
public bool IsValidPoint()
|
{
|
if (!(!double.IsNormal(this.X) || !double.IsNormal(this.Y)))
|
{
|
return true;
|
}
|
return false;
|
}*/
|
|
/// <summary>
|
/// 判断是否为无效点
|
/// </summary>
|
public bool IsInvalidPoint()
|
{
|
if (double.IsNaN(this.X) || double.IsInfinity(this.X) || this.X == double.MinValue || this.X == double.MaxValue)
|
{
|
return true;
|
}
|
if (double.IsNaN(this.Y) || double.IsInfinity(this.Y) || this.Y == double.MinValue || this.Y == double.MaxValue)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 是否沿x轴的射线穿透线段,有交点且在线的左边
|
/// </summary>
|
public bool IsIntersectLineLeft(CurvePoint pt1, CurvePoint pt2)
|
{
|
if (pt1 == null || pt2 == null)
|
{
|
return false;
|
}
|
if (Math.Abs(pt1.Y - pt2.Y) < 0.0001)
|
{
|
if (Math.Abs(this.Y - pt1.Y) < 0.0001)
|
{
|
return true;
|
}
|
}
|
var ymin = UtilsHelper.Min(pt1.Y, pt2.Y);
|
var ymax = UtilsHelper.Max(pt1.Y, pt2.Y);
|
if (this.Y < ymax && this.Y >= ymin)
|
{
|
if (this.X <= (pt1.X + (pt2.X - pt1.X) * (this.Y - pt1.Y) / (pt2.Y - pt1.Y)))
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
|
/// <summary>
|
///
|
/// </summary>
|
public CurvePoint Clone()
|
{
|
return new CurvePoint(this);
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
object ICloneable.Clone()
|
{
|
return this.Clone();
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|