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