namespace IStation.Curve
|
{
|
/// <summary>
|
/// 装置曲线
|
/// </summary>
|
public class DeviceCurve : ICloneable
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public DeviceCurve() { }
|
|
/// <summary>
|
///
|
/// </summary>
|
public DeviceCurve(DeviceCurve rhs)
|
{
|
this.SourceType = rhs.SourceType;
|
this.OriginPoints = rhs.OriginPoints;
|
this.CurveInfo = rhs.CurveInfo;
|
this.CurveExpress = rhs.CurveExpress;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public DeviceCurve(double zeroPointH, IStation.Curve.CurvePoint endPoint, int fitPointNum = 12, eFitType fitType = eFitType.CubicCurve)
|
{
|
SetParabolaPoints(zeroPointH, endPoint);
|
ResetCurveInfo(fitPointNum, fitType);
|
}
|
|
|
|
/// <summary>
|
/// 来源类型
|
/// </summary>
|
public eDeviceSourceType SourceType { get; set; }
|
|
/// <summary>
|
/// 手动输入时是输入的点,二次曲线是两个定义点
|
/// </summary>
|
public List<CurvePoint> OriginPoints { get; set; }
|
|
/// <summary>
|
/// 曲线上的点有可能根据坐标最小值,进行了切割
|
/// </summary>
|
public List<CurvePoint> CurveInfo { get; set; }
|
|
/// <summary>
|
/// 曲线方程
|
/// </summary>
|
public CurveExpress CurveExpress { get; set; }
|
|
/// <summary>
|
/// 获取0流量点扬程
|
/// </summary>
|
public double GetZeroPointH()
|
{
|
if (this.OriginPoints == null || this.OriginPoints.Count < 1)
|
{
|
return default;
|
}
|
return this.OriginPoints[0].Y;
|
}
|
|
/// <summary>
|
/// 设置抛物线点
|
/// </summary>
|
public void SetParabolaPoints(double zeroPointH, IStation.Curve.CurvePoint endPoint)
|
{
|
this.SourceType = eDeviceSourceType.Twice;
|
this.OriginPoints = new List<IStation.Curve.CurvePoint>();
|
this.OriginPoints.Add(new IStation.Curve.CurvePoint(0, zeroPointH));
|
this.OriginPoints.Add(endPoint);
|
}
|
|
/// <summary>
|
/// 重置曲线信息
|
/// </summary>
|
public void ResetCurveInfo(int fitPointNum, eFitType fitType = eFitType.CubicCurve)
|
{
|
if (this.SourceType != eDeviceSourceType.Twice)
|
return;
|
if (this.OriginPoints == null || this.OriginPoints.Count != 2)
|
return;
|
|
double equipCurveZeroH = this.OriginPoints[0].Y;
|
var endPt = this.OriginPoints[1];
|
var points = new List<IStation.Curve.CurvePoint>();
|
double k = (endPt.Y - equipCurveZeroH) / (endPt.X * endPt.X);
|
double minQ = 0;
|
double maxQ = endPt.X;
|
double space = (maxQ - minQ) / (fitPointNum - 1);//11个点
|
for (int i = 0; i < fitPointNum; i++)
|
{
|
double x = space * i + minQ;
|
double y = k * x * x + equipCurveZeroH;
|
points.Add(new IStation.Curve.CurvePoint(x, y));
|
}
|
|
this.CurveInfo = points;
|
this.CurveExpress = IStation.Curve.FitHelper.BuildCurveExpress(points, fitType);
|
}
|
|
/// <summary>
|
/// 获取抛物线系数
|
/// </summary>
|
public double GetParabolaCoeff()
|
{
|
if (this.OriginPoints == null || this.OriginPoints.Count != 2)
|
return default;
|
|
double equipCurveZeroH = OriginPoints[0].Y;
|
var endPt = OriginPoints[1];
|
List<IStation.Curve.CurvePoint> points = new List<IStation.Curve.CurvePoint>();
|
return (endPt.Y - equipCurveZeroH) / (endPt.X * endPt.X);
|
}
|
|
/// <summary>
|
/// 通过 最小值Y重置曲线信息
|
/// </summary>
|
public void ResetCurveInfoByMinY(int fitPointNum, double minY, eFitType fitType = eFitType.CubicCurve)
|
{
|
if (this.SourceType != eDeviceSourceType.Twice)
|
return;
|
if (this.OriginPoints == null || this.OriginPoints.Count != 2)
|
return;
|
if (minY < 0.01)
|
{
|
ResetCurveInfo(fitPointNum, fitType);
|
return;
|
}
|
|
|
double equipCurveZeroH = this.OriginPoints[0].Y;
|
var endPt = this.OriginPoints[1];
|
var points = new List<IStation.Curve.CurvePoint>();
|
double k = (endPt.Y - equipCurveZeroH) / (endPt.X * endPt.X);
|
double minQ = 0;
|
if (minY > equipCurveZeroH)
|
{
|
minQ = Math.Sqrt((minY - equipCurveZeroH) / k);
|
}
|
double maxQ = endPt.X;
|
double space = (maxQ - minQ) / (fitPointNum - 1);
|
for (int i = 0; i < fitPointNum; i++)
|
{
|
double x = space * i + minQ;
|
double y = k * x * x + equipCurveZeroH;
|
points.Add(new IStation.Curve.CurvePoint(x, y));
|
}
|
|
this.CurveInfo = points;
|
}
|
|
|
#region Clone
|
|
/// <summary>
|
///
|
/// </summary>
|
public DeviceCurve Clone()
|
{
|
return new DeviceCurve(this);
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
object ICloneable.Clone()
|
{
|
return Clone();
|
}
|
|
|
#endregion
|
}
|
}
|