using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Linq;
|
using System.Runtime.Serialization;
|
using System.Text;
|
|
namespace IStation.Model
|
{
|
|
/// <summary>
|
/// 曲线表达式
|
/// </summary>
|
[DataContract]
|
public class CurveExpress : ICloneable
|
{
|
#region 构造函数
|
|
public CurveExpress() { }
|
public CurveExpress(CurveExpress rhs)
|
{
|
this.FitPow = rhs.FitPow;
|
this.FitType = rhs.FitType;
|
this.Min = rhs.Min;
|
this.Max = rhs.Max;
|
this.Index0 = rhs.Index0;
|
this.Index1 = rhs.Index1;
|
this.Index2 = rhs.Index2;
|
this.Index3 = rhs.Index3;
|
this.DefinePoints = rhs.DefinePoints?.Select(x => new CurvePoint(x)).ToList();
|
this.IsNull = rhs.IsNull;
|
}
|
|
public CurveExpress(CurveExpress rhs, double ratio_y)
|
{
|
this.FitPow = rhs.FitPow;
|
this.FitType = rhs.FitType;
|
this.Min = rhs.Min;
|
this.Max = rhs.Max;
|
this.Index0 = rhs.Index0 * ratio_y;
|
this.Index1 = rhs.Index1 * ratio_y;
|
this.Index2 = rhs.Index2 * ratio_y;
|
this.Index3 = rhs.Index3 * ratio_y;
|
this.DefinePoints = rhs.DefinePoints?.Select(x => new CurvePoint(x.X, x.Y * ratio_y)).ToList();
|
this.IsNull = rhs.IsNull;
|
}
|
public CurveExpress(string strParas)
|
{
|
if (string.IsNullOrEmpty(strParas))
|
{
|
this.IsNull = true;
|
return;
|
}
|
var str_list = strParas.Split(new string[] { Separator }, StringSplitOptions.RemoveEmptyEntries);
|
var count = str_list.Count();
|
if (count < 8)
|
{
|
this.IsNull = true;
|
return;
|
}
|
this.IsNull = false;
|
this.FitPow = Convert.ToInt32(str_list[0]);
|
this.FitType = (eCurveFitType)Convert.ToInt32(str_list[1]);
|
this.Min = Convert.ToDouble(str_list[2]);
|
this.Max = Convert.ToDouble(str_list[3]);
|
this.Index0 = Convert.ToDouble(str_list[4]);
|
this.Index1 = Convert.ToDouble(str_list[5]);
|
this.Index2 = Convert.ToDouble(str_list[6]);
|
this.Index3 = Convert.ToDouble(str_list[7]);
|
if (count > 8)
|
{
|
this.DefinePoints = CurvePoint.ToList(str_list[8]);
|
}
|
}
|
public CurveExpress(List<CurvePoint> points)
|
{
|
ResetCurve(points, eCurveFitType.CubicCurve, false);
|
}
|
public CurveExpress(List<CurvePoint> points, bool savePoints)
|
{
|
ResetCurve(points, eCurveFitType.CubicCurve, savePoints);
|
}
|
public CurveExpress(List<CurvePoint> points, eCurveFitType fitType)
|
{
|
ResetCurve(points, fitType, false);
|
}
|
public CurveExpress(List<CurvePoint> points, eCurveFitType fitType, bool savePoints)
|
{
|
ResetCurve(points, fitType, savePoints);
|
}
|
public CurveExpress(List<CurvePoint> points, int fitPow)
|
{
|
ResetCurve(points, fitPow, false);
|
}
|
public CurveExpress(List<CurvePoint> points, int fitPow, bool savePoints)
|
{
|
ResetCurve(points, fitPow, savePoints);
|
}
|
public static CurveExpress ToParameter(string strStore)
|
{
|
if (string.IsNullOrEmpty(strStore))
|
return null;
|
return new CurveExpress(strStore);
|
}
|
public static CurveExpress ToParameter(List<CurvePoint> points, eCurveFitType fitType)
|
{
|
if (points == null || points.Count() <= 3)
|
return null;
|
return new CurveExpress(points, fitType);
|
}
|
public static CurveExpress ToParameter(List<CurvePoint> points)
|
{
|
if (points == null || points.Count() <= 3)
|
return null;
|
return new CurveExpress(points);
|
}
|
/// <summary>
|
/// 重置曲线
|
/// </summary>
|
public virtual void ResetCurve(CurveExpress rhs)
|
{
|
this.FitPow = rhs.FitPow;
|
this.FitType = rhs.FitType;
|
this.Min = rhs.Min;
|
this.Max = rhs.Max;
|
this.Index0 = rhs.Index0;
|
this.Index1 = rhs.Index1;
|
this.Index2 = rhs.Index2;
|
this.Index3 = rhs.Index3;
|
this.DefinePoints = rhs.DefinePoints?.Select(x => new CurvePoint(x)).ToList();
|
this.IsNull = rhs.IsNull;
|
}
|
|
/// <summary>
|
/// 重置曲线
|
/// </summary>
|
public virtual void ResetCurve(List<CurvePoint> points, eCurveFitType fitType, bool savePoints = false)
|
{
|
var express = FitCurveHelper.BuildCurveExpress(points, fitType);
|
if (express == null)
|
{
|
this.IsNull = true;
|
return;
|
}
|
if (express.IsNull)
|
{
|
this.IsNull = true;
|
return;
|
}
|
this.FitType = express.FitType;
|
this.FitPow = express.FitPow;
|
this.Min = express.Min;
|
this.Max = express.Max;
|
this.Index0 = express.Index0;
|
this.Index1 = express.Index1;
|
this.Index2 = express.Index2;
|
this.Index3 = express.Index3;
|
this.IsNull = express.IsNull;
|
if (savePoints)
|
{
|
this.DefinePoints = express.DefinePoints;
|
}
|
else if (fitType == eCurveFitType.ThroughPoint)
|
{
|
this.DefinePoints = express.DefinePoints;
|
}
|
}
|
|
/// <summary>
|
/// 重置曲线
|
/// </summary>
|
public virtual void ResetCurve(List<CurvePoint> points, int fitPow, bool savePoints = false)
|
{
|
var fitType = GetFitType(fitPow);
|
this.ResetCurve(points, fitType, savePoints);
|
}
|
|
|
#endregion
|
|
#region 静态值
|
|
public const string Separator = "#";
|
|
#endregion
|
|
#region 属性
|
|
/// <summary>
|
/// 拟合次数
|
/// </summary>
|
[DataMember]
|
public int FitPow
|
{
|
get { return fitPow; }
|
set { fitPow = value; }
|
}
|
protected int fitPow = 3;
|
|
/// <summary>
|
/// 拟合类型
|
/// </summary>
|
[DataMember]
|
public eCurveFitType FitType
|
{
|
get { return fitType; }
|
set { fitType = value; }
|
}
|
protected eCurveFitType fitType = eCurveFitType.CubicCurve;
|
|
/// <summary>
|
/// 最大值
|
/// </summary>
|
[DataMember]
|
public double Max
|
{
|
get { return max; }
|
set { max = value; }
|
}
|
protected double max;
|
|
/// <summary>
|
/// 最小值
|
/// </summary>
|
[DataMember]
|
public double Min
|
{
|
get { return min; }
|
set { min = value; }
|
}
|
protected double min;
|
|
/// <summary>
|
/// 0次系数
|
/// </summary>
|
[DataMember]
|
public double Index0
|
{
|
get { return index0; }
|
set { index0 = value; }
|
}
|
protected double index0;
|
|
/// <summary>
|
/// 1次系数
|
/// </summary>
|
[DataMember]
|
public double Index1
|
{
|
get { return index1; }
|
set { index1 = value; }
|
}
|
protected double index1;
|
|
/// <summary>
|
/// 2次系数
|
/// </summary>
|
[DataMember]
|
public double Index2
|
{
|
get { return index2; }
|
set { index2 = value; }
|
}
|
protected double index2;
|
|
/// <summary>
|
/// 3次系数
|
/// </summary>
|
[DataMember]
|
public double Index3
|
{
|
get { return index3; }
|
set { index3 = value; }
|
}
|
protected double index3;
|
|
/// <summary>
|
/// 4次系数
|
/// </summary>
|
[DataMember]
|
public double Index4
|
{
|
get { return index4; }
|
set { index4 = value; }
|
}
|
protected double index4;
|
|
/// <summary>
|
/// 定义点
|
/// </summary>
|
[DataMember]
|
public List<CurvePoint> DefinePoints
|
{
|
get { return definePoints; }
|
set { definePoints = value; }
|
}
|
protected List<CurvePoint> definePoints = null;
|
|
/// <summary>
|
/// 是否为空
|
/// </summary>
|
[DataMember]
|
public bool IsNull
|
{
|
get { return isNull; }
|
set { isNull = value; }
|
}
|
protected bool isNull;
|
|
|
#endregion
|
|
|
/// <summary>
|
/// 转化为保存字符串
|
/// </summary>
|
public string ToDsString()
|
{
|
var str_list = new List<string>();
|
str_list.Add(this.FitPow.ToString());
|
str_list.Add(((int)this.FitType).ToString());
|
str_list.Add(this.Min.ToString());
|
str_list.Add(this.Max.ToString());
|
//str_list.Add(this.Index0.ToString());
|
//str_list.Add(this.Index1.ToString("0.00000"));
|
//str_list.Add(this.Index2.ToString("0.0000000000"));
|
//str_list.Add(this.Index3.ToString("0.00000000000000"));
|
|
//nsx
|
var dc = new DoubleConverter();
|
str_list.Add(dc.ConvertToString(this.Index0));
|
str_list.Add(dc.ConvertToString(this.Index1));
|
str_list.Add(dc.ConvertToString(this.Index2));
|
str_list.Add(dc.ConvertToString(this.Index3));
|
|
if (this.DefinePoints != null && this.DefinePoints.Count > 0)
|
{
|
str_list.Add(this.DefinePoints.ToDsString());
|
}
|
return string.Join(Separator, str_list);
|
}
|
public static string ToDsString(CurveExpress model)
|
{
|
if (model == null)
|
return null;
|
else
|
return model.ToDsString();
|
}
|
public static string ToDsString(List<CurvePoint> points)
|
{
|
if (points == null || points.Count() < 2)
|
return null;
|
else
|
return new CurveExpress(points).ToDsString();
|
}
|
object ICloneable.Clone()
|
{
|
return Clone();
|
}
|
|
public CurveExpress Clone()
|
{
|
return new CurveExpress(this);
|
}
|
|
/// <summary>
|
/// 是否在内部
|
/// </summary>
|
public bool IsInterior(double x)
|
{
|
if (x < Min)
|
return false;
|
if (x > Max)
|
return false;
|
return true;
|
}
|
|
/// <summary>
|
/// 获取拟合次方
|
/// </summary>
|
public static int GetFitPow(eCurveFitType fitType)
|
{
|
switch (fitType)
|
{
|
case eCurveFitType.FourM: return 4;
|
case eCurveFitType.CubicCurve: return 3;
|
case eCurveFitType.ConicCurve: return 2;
|
case eCurveFitType.ConicCurveB0: return 2;
|
case eCurveFitType.LinearCurve: return 1;
|
case eCurveFitType.ThroughPoint: return 0;
|
default: return 3;
|
}
|
}
|
|
/// <summary>
|
/// 获取拟合类型
|
/// </summary>
|
public static eCurveFitType GetFitType(int fitPow)
|
{
|
switch (fitPow)
|
{
|
case 4: return eCurveFitType.FourM;
|
case 3: return eCurveFitType.CubicCurve;
|
case 2: return eCurveFitType.ConicCurve;
|
case 1: return eCurveFitType.LinearCurve;
|
case 0: return eCurveFitType.ThroughPoint;
|
default: return eCurveFitType.CubicCurve;
|
}
|
}
|
|
/// <summary>
|
/// 获取拟合点
|
/// </summary>
|
public double GetFitPointY(double x)
|
{
|
return FitCurveHelper.GetFitPointY(this, x);
|
}
|
|
/// <summary>
|
/// 获取拟合点
|
/// </summary>
|
public List<CurvePoint> GetFitPoints(int pointNumber = 20)
|
{
|
if (this.IsNull)
|
return default;
|
return FitCurveHelper.GetFitPoints(this, pointNumber);
|
}
|
|
/// <summary>
|
/// 通过区间内拟合点
|
/// </summary>
|
public List<CurvePoint> GetFitPointsByRange(double minX, double maxX, int pointNumber = 20)
|
{
|
if (this.IsNull)
|
return default;
|
return FitCurveHelper.GetFitPointsByRange(this, minX, maxX, pointNumber);
|
}
|
|
/// <summary>
|
/// 获取拟合点
|
/// </summary>
|
public List<CurvePoint> GetFitPointsByExtend(double ratioExtend, int pointNumber = 20)
|
{
|
if (this.IsNull)
|
return default;
|
return GetFitPointsByRange(this.min, this.max * ratioExtend, pointNumber);
|
}
|
|
/// <summary>
|
/// 获取第一个拟合点
|
/// </summary>
|
public CurvePoint GetFirstFitPoint()
|
{
|
return new CurvePoint(this.Min, GetFitPointY(this.Min));
|
}
|
|
/// <summary>
|
/// 获取最后一个拟合点
|
/// </summary>
|
public CurvePoint GetLastFitPoint()
|
{
|
return new CurvePoint(this.Max, GetFitPointY(this.Max));
|
}
|
|
/// <summary>
|
/// 获取零点的Y值
|
/// </summary>
|
public double GetZeroFitPointY()
|
{
|
return this.Index0;
|
}
|
|
/// <summary>
|
/// 转换为Model
|
/// </summary>
|
public static CurveExpress ToModel(string strParas)
|
{
|
if (string.IsNullOrEmpty(strParas))
|
return default;
|
var express = new CurveExpress(strParas);
|
if (express == null)
|
return default;
|
return express;
|
}
|
|
/// <summary>
|
/// 是否相等
|
/// </summary>
|
public bool IsEquals(CurveExpress rhs)
|
{
|
if (rhs == null)
|
return false;
|
if (rhs.ToDsString().Equals(this.ToDsString()))
|
return true;
|
else
|
return false;
|
}
|
|
/// <summary>
|
/// 是否为Zero表达式
|
/// </summary>
|
public bool IsZeroExpress()
|
{
|
if (this.Index0 != 0)
|
return false;
|
if (this.Index1 != 0)
|
return false;
|
if (this.Index2 != 0)
|
return false;
|
if (this.Index3 != 0)
|
return false;
|
return true;
|
}
|
|
/// <summary>
|
/// 通过 X转换
|
/// </summary>
|
public CurveExpress TransferX(double ratioX)
|
{
|
var fitPoints = this.GetFitPoints();
|
fitPoints = fitPoints?.Select(x => new CurvePoint(x.X * ratioX, x.Y)).ToList();
|
if (fitPoints == null || fitPoints.Count < 1)
|
return default;
|
var exp = new CurveExpress(fitPoints, this.FitType);
|
var definePoints = this.DefinePoints?.Select(x => new CurvePoint(x.X * ratioX, x.Y)).ToList();
|
if (definePoints != null && definePoints.Count > 0)
|
exp.DefinePoints = definePoints;
|
return exp;
|
}
|
|
/// <summary>
|
/// 相似换算(speed_ratio = 新的转速 除以 老的转速)
|
/// </summary>
|
public CurveExpress SimuBySpeed(eFeatCurveType featType, double speed_ratio, int pointNumber = 20)
|
{
|
double space = (this.Max - this.Min) / (pointNumber - 1);
|
switch (featType)
|
{
|
case eFeatCurveType.QH:
|
{
|
List<CurvePoint> pointInfo60 = new List<CurvePoint>();
|
|
for (int i = 0; i < pointNumber; i++)
|
{
|
double q50 = space * i + this.Min;
|
double q60 = q50 * speed_ratio;
|
double Y50 = GetFitPointY(q50);
|
pointInfo60.Add(new CurvePoint() { X = q60, Y = Y50 * speed_ratio * speed_ratio });
|
}
|
|
var new_curve = new CurveExpress(pointInfo60, this.FitType);
|
new_curve.DefinePoints = this.DefinePoints?.Select(x => new CurvePoint() { X = x.X * speed_ratio, Y = x.Y * speed_ratio * speed_ratio }).ToList();
|
return new_curve;
|
}
|
case eFeatCurveType.QE:
|
{
|
List<CurvePoint> pointInfo60 = new List<CurvePoint>();
|
|
for (int i = 0; i < pointNumber; i++)
|
{
|
double q50 = space * i + this.Min;
|
double q60 = q50 * speed_ratio;
|
double Y50 = GetFitPointY(q50);
|
pointInfo60.Add(new CurvePoint() { X = q60, Y = Y50 });
|
}
|
|
var new_curve = new CurveExpress(pointInfo60, this.FitType);
|
return new_curve;
|
}
|
case eFeatCurveType.QP:
|
{
|
List<CurvePoint> pointInfo60 = new List<CurvePoint>();
|
|
for (int i = 0; i < pointNumber; i++)
|
{
|
double q50 = space * i + this.Min;
|
double q60 = q50 * speed_ratio;
|
double Y50 = GetFitPointY(q50);
|
pointInfo60.Add(new CurvePoint() { X = q60, Y = Y50 * speed_ratio * speed_ratio * speed_ratio });
|
}
|
|
var new_curve = new CurveExpress(pointInfo60);
|
new_curve.DefinePoints = this.DefinePoints?.Select(x => new CurvePoint() { X = x.X * speed_ratio, Y = x.Y * speed_ratio * speed_ratio * speed_ratio }).ToList();
|
return new_curve;
|
}
|
default:
|
{
|
List<CurvePoint> pointInfo60 = new List<CurvePoint>();
|
|
for (int i = 0; i < pointNumber; i++)
|
{
|
double q50 = space * i + this.Min;
|
double q60 = q50 * speed_ratio;
|
double Y50 = GetFitPointY(q50);
|
pointInfo60.Add(new CurvePoint() { X = q60, Y = Y50 });
|
}
|
|
var new_curve = new CurveExpress(pointInfo60);
|
new_curve.DefinePoints = this.DefinePoints?.Select(x => new CurvePoint() { X = x.X * speed_ratio, Y = x.Y }).ToList();
|
return new_curve;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 50 到 60
|
/// </summary>
|
public CurveExpress SimuFrom50To60(eFeatCurveType featType, int pointNumber = 20)
|
{
|
return SimuBySpeed(featType, 1.2, pointNumber);
|
}
|
|
|
/// <summary>
|
/// 曲线方程:用于显示
|
/// </summary>
|
public string GetCurveFunction(string xName = "Q")
|
{
|
//double signValue = 0;
|
//int value = 0;
|
|
StringBuilder sb = new StringBuilder();
|
|
//sb.Append(this.index0.ToString("G"));
|
//sb.Append(this.index0.ToString("0.00E+000"));//ToString("G"));
|
sb.Append(Math.Abs(this.Index0).ToString("0.00"));//.ToString("G"));
|
|
if (this.Index1 > 0)
|
sb.Append(" + ");
|
else
|
sb.Append(" - ");
|
//GetFuncScientificValue(1,Math.Abs(index1),ref signValue,ref value);
|
//sb.AppendFormat("{0}E{1}",signValue,value);
|
sb.Append(Math.Abs(this.Index1).ToString("0.0000"));//.ToString("G"));
|
sb.Append(" * ");
|
sb.Append(xName);
|
|
|
if (this.Index2 > 0)
|
sb.Append(" + ");
|
else
|
sb.Append(" - ");
|
//GetFuncScientificValue(2,Math.Abs(index2),ref signValue,ref value);
|
//sb.AppendFormat("{0}E{1}",signValue,value);
|
//sb.Append(Math.Round(Math.Abs(this.index2),4).ToString("G"));//.ToString("G"));
|
sb.Append(Math.Abs(this.Index2).ToString("0.000000000"));//.ToString("G"));
|
sb.Append(" * ");
|
sb.Append(xName);
|
sb.Append("^2 ");
|
|
|
if (this.Index3 > 0)
|
sb.Append(" + ");
|
else
|
sb.Append(" - ");
|
//GetFuncScientificValue(3,Math.Abs(index3),ref signValue,ref value);
|
//sb.AppendFormat("{0}E{1}",signValue,value);
|
//sb.Append(Math.Abs(this.index3).ToString("G"));//.ToString("G"));
|
sb.Append(Math.Abs(this.Index3).ToString("0.000000000000"));//.ToString("G"));
|
sb.Append(" * ");
|
sb.Append(xName);
|
sb.Append("^3 ");
|
|
return sb.ToString();
|
}
|
|
public System.Drawing.Image GetCurveFunctionImg(string xName = "Q")//, int Width = 1000, int Height = 150)
|
{
|
return CreatImage(this.index0, this.index1, this.index2, this.index3, xName);
|
}
|
|
public static System.Drawing.Image CreatImage(double firstCoefficient, double secondCoefficient, double thirdCoefficient, double lastCoefficient, string Variable = "Q")//, int Width = 1000, int Height = 150 )
|
{
|
int ImageWidth = 900;
|
int ImageHeight = 45;
|
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(ImageWidth, ImageHeight);
|
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
|
graphics.Clear(System.Drawing.Color.White);
|
|
#region 属性及变量
|
System.Drawing.Color textColor = System.Drawing.Color.Brown;
|
float textWidth = 2f;
|
|
System.Drawing.Font txtFont = new System.Drawing.Font("宋体", 16f);
|
System.Drawing.Brush txtbrush = new System.Drawing.SolidBrush(System.Drawing.Color.Brown);
|
System.Drawing.Font txtIndexFont = new System.Drawing.Font("宋体", 10f);
|
//string IndependentVariable = "h";
|
//string textY = "";// IndependentVariable + " " + "=";
|
string txt1 = "";
|
string txt2 = "";
|
string txt3 = "";
|
string txt0 = "";
|
double firstCoeff = 0;
|
int firstIndex = 0;
|
double secondCoeff = 0;
|
int secondIndex = 0;
|
double thirdCoeff = 0;
|
int thirdIndex = 0;
|
double lastCoeff = 0;
|
int lastIndex = 0;
|
#endregion
|
|
#region 拆分系数
|
|
//firstCoeff =Convert .ToDouble ( GetRealValueToCoefficient(firstCoefficient,0));
|
//firstIndex = GetCoefficientIndex(firstCoefficient);
|
GetFuncScientificValue(0, firstCoefficient, ref firstCoeff, ref firstIndex);
|
|
// secondCoeff = Convert.ToDouble(GetRealValueToCoefficient(secondCoefficient,1));
|
// secondIndex = GetCoefficientIndex(secondCoefficient);
|
GetFuncScientificValue(1, secondCoefficient, ref secondCoeff, ref secondIndex);
|
|
// thirdCoeff = Convert.ToDouble(GetRealValueToCoefficient(thirdCoefficient,2));
|
// thirdIndex = GetCoefficientIndex(thirdCoefficient);
|
GetFuncScientificValue(2, thirdCoefficient, ref thirdCoeff, ref thirdIndex);
|
|
// lastCoeff = Convert.ToDouble(GetRealValueToCoefficient(lastCoefficient,3));
|
// lastIndex = GetCoefficientIndex(lastCoefficient);
|
GetFuncScientificValue(3, lastCoefficient, ref lastCoeff, ref lastIndex);
|
|
#endregion
|
|
#region 设置系数及运算符号
|
if (firstCoeff >= 0)
|
{
|
if (firstIndex > 1 || firstIndex <= -1)
|
txt0 = " " + firstCoeff.ToString("0.00") + " " + "×" + " " + "10";
|
if (firstIndex == 0 || firstIndex == 1)
|
{
|
txt0 = " " + firstCoefficient.ToString("0.00");
|
}
|
|
}
|
else
|
{
|
if (firstIndex > 1 || firstIndex <= -1)
|
txt0 = " " + "- " + (firstCoeff * (-1)).ToString("0.00") + " " + "×" + " " + "10";
|
if (firstIndex == 0 || firstIndex == 1)
|
{
|
txt0 = " " + "- " + (firstCoeff * (-1)).ToString("0.00");
|
}
|
}
|
|
if (secondCoefficient >= 0)
|
{
|
if (secondIndex > 1 || secondIndex <= -1)
|
txt1 = " " + "+" + " " + secondCoeff.ToString("0.00000") + " " + "×" + " " + "10";
|
if (secondIndex == 0 || secondIndex == 1)
|
txt1 = " " + "+ " + secondCoeff.ToString("0.00000");
|
}
|
else
|
{
|
if (secondIndex > 1 || secondIndex <= -1)
|
txt1 = " " + "- " + (secondCoeff * (-1)).ToString("0.00000") + " " + "×" + " " + "10";
|
if (secondIndex == 0 || secondIndex == 1)
|
txt1 = " " + "- " + (secondCoeff * (-1)).ToString("0.00000");
|
}
|
|
if (thirdCoefficient >= 0)
|
{
|
if (thirdIndex > 1 || thirdIndex <= -1)
|
txt2 = " " + "+" + " " + thirdCoeff.ToString() + " " + "×" + " " + "10";
|
if (thirdIndex == 0 || thirdIndex == 1)
|
txt2 = " " + "+ " + (thirdCoeff).ToString();
|
}
|
else
|
{
|
if (thirdIndex > 1 || thirdIndex <= -1)
|
txt2 = " " + "- " + (thirdCoeff * (-1)).ToString() + " " + "×" + " " + "10";
|
if (thirdIndex == 0 || thirdIndex == 1)
|
txt2 = " " + "- " + (thirdCoeff * (-1)).ToString();
|
}
|
|
if (lastCoefficient >= 0)
|
{
|
if (lastIndex > 1 || lastIndex <= -1)
|
txt3 = " " + "+" + " " + lastCoeff.ToString() + " " + "×" + " " + "10";
|
if (lastIndex == 0 || lastIndex == 1)
|
txt3 = " " + "+ " + (lastCoeff).ToString();
|
}
|
else
|
{
|
if (lastIndex > 1 || lastIndex <= -1)
|
txt3 = " " + "- " + (lastCoeff * (-1)).ToString() + " " + "×" + " " + "10";
|
if (lastIndex == 0 || lastIndex == 1)
|
txt3 = " " + "- " + (lastCoeff * (-1)).ToString();
|
}
|
#endregion
|
|
System.Drawing.PointF pt = new System.Drawing.PointF();
|
System.Drawing.PointF pt0 = new System.Drawing.PointF();
|
System.Drawing.PointF pt1 = new System.Drawing.PointF();
|
System.Drawing.PointF pt2 = new System.Drawing.PointF();
|
System.Drawing.PointF pt3 = new System.Drawing.PointF();
|
System.Drawing.PointF pt4 = new System.Drawing.PointF();
|
System.Drawing.PointF pt5 = new System.Drawing.PointF();
|
System.Drawing.PointF pt6 = new System.Drawing.PointF();
|
System.Drawing.PointF pt7 = new System.Drawing.PointF();
|
System.Drawing.PointF pt8 = new System.Drawing.PointF();
|
System.Drawing.PointF pt9 = new System.Drawing.PointF();
|
System.Drawing.PointF pt10 = new System.Drawing.PointF();
|
System.Drawing.PointF pt11 = new System.Drawing.PointF();
|
System.Drawing.PointF pt12 = new System.Drawing.PointF();
|
|
using (System.Drawing.Pen pen = new System.Drawing.Pen(textColor, textWidth))
|
{
|
#region 绘制
|
pt.X = 5;
|
pt.Y = ImageHeight / 2 - txtFont.Height / 2;
|
//graphics.DrawString(textY, txtFont, txtbrush, pt);
|
//var Length = 0;// graphics.MeasureString(textY, txtFont);
|
|
//0次方
|
#region 0次方
|
pt0.X = pt.X - txtFont.Height / 4;//+ (float)Length.Width
|
pt0.Y = pt.Y;
|
graphics.DrawString(txt0, txtFont, txtbrush, pt0);
|
var length0 = graphics.MeasureString(txt0, txtFont);
|
|
float length1 = 0;
|
|
if (firstIndex > 1 || firstIndex <= -1)
|
{
|
pt1.X = pt0.X + length0.Width - txtIndexFont.Height / 2;
|
pt1.Y = pt0.Y - txtIndexFont.Height / 2;
|
graphics.DrawString(firstIndex.ToString(), txtIndexFont, txtbrush, pt1);
|
length1 = graphics.MeasureString(firstIndex.ToString(), txtIndexFont).Width;
|
}
|
#endregion
|
|
//一次方
|
#region 一次方
|
float length2 = 0;
|
if (pt1.X > 0)
|
{
|
pt2.X = pt1.X + length1 - txtFont.Height / 4;
|
pt2.Y = pt0.Y;
|
graphics.DrawString(txt1, txtFont, txtbrush, pt2);
|
length2 = graphics.MeasureString(txt1.ToString(), txtFont).Width;
|
}
|
else
|
{
|
pt2.X = pt0.X + length0.Width - txtIndexFont.Height / 2 + length1 - txtFont.Height / 4;
|
pt2.Y = pt0.Y;
|
graphics.DrawString(txt1, txtFont, txtbrush, pt2);
|
length2 = graphics.MeasureString(txt1.ToString(), txtFont).Width;
|
}
|
|
float length3 = 0;
|
if (secondIndex > 1 || secondIndex <= -1)
|
{
|
pt3.X = pt2.X + length2 - txtIndexFont.Height / 2;
|
pt3.Y = pt0.Y - txtIndexFont.Height / 2;
|
graphics.DrawString(secondIndex.ToString(), txtIndexFont, txtbrush, pt3);
|
length3 = graphics.MeasureString(secondIndex.ToString(), txtIndexFont).Width;
|
}
|
|
if (pt3.X > 0)
|
{
|
pt4.X = pt3.X + length3 - txtFont.Height / 2 + txtIndexFont.Height / 2;
|
pt4.Y = pt.Y;
|
graphics.DrawString(Variable, txtFont, txtbrush, pt4);
|
}
|
else
|
{
|
pt4.X = pt2.X + length2 + length3 - txtFont.Height / 2 + txtIndexFont.Height / 4;
|
pt4.Y = pt.Y;
|
graphics.DrawString(Variable, txtFont, txtbrush, pt4);
|
}
|
var length4 = graphics.MeasureString(Variable, txtFont);
|
#endregion
|
|
//二次方
|
#region 二次方
|
pt5.X = pt4.X + length4.Width - txtFont.Height / 4;
|
pt5.Y = pt4.Y;
|
graphics.DrawString(txt2, txtFont, txtbrush, pt5);
|
var length5 = graphics.MeasureString(txt2, txtFont);
|
|
float length6 = 0;
|
if (thirdIndex <= -1 || thirdIndex > 1)
|
{
|
pt6.X = pt5.X + length5.Width - txtIndexFont.Height / 2;
|
pt6.Y = pt0.Y - txtIndexFont.Height / 2;
|
graphics.DrawString(thirdIndex.ToString(), txtIndexFont, txtbrush, pt6);
|
length6 = graphics.MeasureString(thirdIndex.ToString(), txtIndexFont).Width;
|
}
|
|
if (pt6.X > 0)
|
{
|
pt7.X = pt6.X + length6 - txtFont.Height / 2 + txtIndexFont.Height / 2;
|
pt7.Y = pt5.Y;
|
graphics.DrawString(Variable, txtFont, txtbrush, pt7);
|
}
|
else
|
{
|
pt7.X = pt5.X + length5.Width + length6 - txtFont.Height / 2 + txtIndexFont.Height / 4;
|
pt7.Y = pt5.Y;
|
graphics.DrawString(Variable, txtFont, txtbrush, pt7);
|
}
|
var length7 = graphics.MeasureString(Variable, txtFont);
|
|
pt8.X = pt7.X + length7.Width - txtIndexFont.Height / 3;
|
pt8.Y = pt0.Y - txtIndexFont.Height / 2;
|
graphics.DrawString("2", txtIndexFont, txtbrush, pt8);
|
var length8 = graphics.MeasureString("2", txtIndexFont);
|
#endregion
|
|
//三次方
|
#region 三次方
|
pt9.X = pt8.X + length8.Width - txtFont.Height / 4;
|
pt9.Y = pt4.Y;
|
graphics.DrawString(txt3, txtFont, txtbrush, pt9);
|
var length9 = graphics.MeasureString(txt3, txtFont);
|
float length10 = 0;
|
if (lastIndex > 1 || lastIndex <= -1)
|
{
|
pt10.X = pt9.X + length9.Width - txtIndexFont.Height / 2;
|
pt10.Y = pt0.Y - txtIndexFont.Height / 2;
|
graphics.DrawString(lastIndex.ToString(), txtIndexFont, txtbrush, pt10);
|
length10 = graphics.MeasureString(lastIndex.ToString(), txtIndexFont).Width;
|
}
|
if (pt10.X > 0)
|
{
|
pt11.X = pt10.X + length10 - txtFont.Height / 2 + txtIndexFont.Height / 2;
|
pt11.Y = pt5.Y;
|
graphics.DrawString(Variable, txtFont, txtbrush, pt11);
|
}
|
else
|
{
|
pt11.X = pt9.X + length9.Width + length10 - txtFont.Height / 2 + txtIndexFont.Height / 4;
|
pt11.Y = pt5.Y;
|
graphics.DrawString(Variable, txtFont, txtbrush, pt11);
|
}
|
var length11 = graphics.MeasureString(Variable, txtFont);
|
|
pt12.X = pt11.X + length11.Width - txtIndexFont.Height / 3;
|
pt12.Y = pt0.Y - txtIndexFont.Height / 2;
|
graphics.DrawString("3", txtIndexFont, txtbrush, pt12);
|
var length12 = graphics.MeasureString("3", txtIndexFont);
|
#endregion
|
#endregion
|
}
|
graphics.Dispose();
|
txtFont.Dispose();
|
txtbrush.Dispose();
|
txtIndexFont.Dispose();
|
return bitmap;
|
|
}
|
|
private static void GetFuncScientificValue(int FunctionIndex,
|
double FunctionCoeff, ref double signValue, ref int indexValue)
|
{
|
string strList = "";
|
if (FunctionIndex == 0)
|
{
|
strList = FunctionCoeff.ToString("0.000e+000");
|
}
|
else if (FunctionIndex == 1)
|
{
|
strList = FunctionCoeff.ToString("0.000000e+000");
|
}
|
else if (FunctionIndex == 2)
|
{
|
strList = FunctionCoeff.ToString("#.#########e+000");
|
}
|
else if (FunctionIndex == 3)
|
{
|
strList = FunctionCoeff.ToString("#.############e+000");
|
}
|
string[] st1 = null;
|
st1 = strList.Split('e');
|
signValue = Convert.ToDouble(st1[0]);
|
indexValue = Convert.ToInt32(st1[1]);
|
}
|
|
|
public static List<IStation.Model.CurvePoint> ToPoints(CurveExpress curve, int PointNum)
|
{
|
if (curve.isNull)
|
return null;
|
if (curve.FitPow <= 0)
|
return new IStation.Model.CurvePointList(curve.definePoints);
|
|
return IStation.Model.FitCurveHelper.GetFitPoints(curve, PointNum);
|
}
|
|
public List<IStation.Model.CurvePoint> ToPoints(int PointNum)
|
{
|
if (this.isNull)
|
return null;
|
if (this.FitPow <= 0)
|
return new IStation.Model.CurvePointList(this.definePoints);
|
|
return IStation.Model.FitCurveHelper.GetFitPoints(this, PointNum);
|
}
|
|
public List<IStation.Model.CurvePoint> ToPoints(double xMin, double xMax, int PointNum)
|
{
|
if (this.isNull)
|
return null;
|
if (this.FitPow <= 0)
|
return new IStation.Model.CurvePointList(this.definePoints);
|
|
return IStation.Model.FitCurveHelper.GetFitPointsByRange(this, xMin, xMax, PointNum);
|
}
|
|
|
|
|
|
}
|
}
|