namespace Yw.Curve
|
{
|
/// <summary>
|
/// 曲线拟合辅助类
|
/// </summary>
|
public class FitHelper
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public FitHelper(CurveExpress express)
|
{
|
switch (express.FitType)
|
{
|
case eFitType.ThroughPoint: _fitPoint = new TwinRelateCurve0(express); break;
|
case eFitType.LinearCurve: _fitPoint = new TwinRelateCurve1(express); break;
|
case eFitType.ConicCurveB0: _fitPoint = new TwinRelateCurve2B0(express); break;
|
case eFitType.ConicCurve: _fitPoint = new TwinRelateCurve2M(express); break;
|
case eFitType.CubicCurve: _fitPoint = new TwinRelateCurve3M(express); break;
|
case eFitType.FourM: _fitPoint = new TwinRelateCurve4M(express); break;
|
default: break;
|
}
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public FitHelper(List<CurvePoint> points, eFitType fitType = eFitType.CubicCurve)
|
{
|
switch (fitType)
|
{
|
case eFitType.ThroughPoint: _fitPoint = new TwinRelateCurve0(points); break;
|
case eFitType.LinearCurve: _fitPoint = new TwinRelateCurve1(points); break;
|
case eFitType.ConicCurveB0: _fitPoint = new TwinRelateCurve2B0(points); break;
|
case eFitType.ConicCurve: _fitPoint = new TwinRelateCurve2M(points); break;
|
case eFitType.CubicCurve: _fitPoint = new TwinRelateCurve3M(points); break;
|
case eFitType.FourM: _fitPoint = new TwinRelateCurve4M(points); break;
|
default: break;
|
}
|
}
|
|
|
//拟合接口对象
|
private IFitPoint _fitPoint = null;
|
|
/// <summary>
|
/// 获取曲线拟合点Y值
|
/// </summary>
|
public double GetFitPointY(double x)
|
{
|
if (_fitPoint == null)
|
return default;
|
return _fitPoint.GetFitPointY(x);
|
}
|
|
/// <summary>
|
/// 获取拟合点列表
|
/// </summary>
|
public List<CurvePoint> GetFitPoints(int pointNumber)
|
{
|
if (_fitPoint == null)
|
return default;
|
return _fitPoint.GetFitPoints(pointNumber);
|
}
|
|
/// <summary>
|
/// 通过X区间获取拟合点列表
|
/// </summary>
|
public List<CurvePoint> GetFitPointsByXRange(double minX, double maxX, int pointNumber)
|
{
|
if (_fitPoint == null)
|
return default;
|
return _fitPoint.GetFitPointsByXRange(minX, maxX, pointNumber);
|
}
|
|
/// <summary>
|
/// 获取拟合点Y
|
/// </summary>
|
public static double GetFitPointY(CurveExpress express, double x)
|
{
|
if (express == null)
|
return default;
|
var helper = new FitHelper(express);
|
return helper.GetFitPointY(x);
|
}
|
|
/// <summary>
|
/// 获取拟合点
|
/// </summary>
|
public static List<CurvePoint> GetFitPoints(CurveExpress express, int pointNumber)
|
{
|
if (express == null)
|
return default;
|
var helper = new FitHelper(express);
|
return helper.GetFitPoints(pointNumber);
|
}
|
|
/// <summary>
|
/// 获取拟合点
|
/// </summary>
|
public static List<CurvePoint> GetFitPointsByXRange(CurveExpress express, double minX, double maxX, int pointNumber)
|
{
|
if (express == null)
|
return default;
|
var helper = new FitHelper(express);
|
return helper.GetFitPointsByXRange(minX, maxX, pointNumber);
|
}
|
|
/// <summary>
|
/// 获取拟合次方
|
/// </summary>
|
public static int GetFitPow(eFitType fitType)
|
{
|
switch (fitType)
|
{
|
case eFitType.CubicCurve: return 3;
|
case eFitType.ConicCurve: return 2;
|
case eFitType.ConicCurveB0: return 2;
|
case eFitType.LinearCurve: return 1;
|
case eFitType.ThroughPoint: return 0;
|
case eFitType.FourM: return 4;
|
default: return 3;
|
}
|
}
|
|
/// <summary>
|
/// 获取拟合类型
|
/// </summary>
|
public static eFitType GetFitType(int fitPow)
|
{
|
switch (fitPow)
|
{
|
case 3: return eFitType.CubicCurve;
|
case 2: return eFitType.ConicCurve;
|
case 1: return eFitType.LinearCurve;
|
case 0: return eFitType.ThroughPoint;
|
case 4: return eFitType.FourM;
|
default: return eFitType.CubicCurve;
|
}
|
}
|
|
/// <summary>
|
/// 创建曲线表达式
|
/// </summary>
|
public static CurveExpress BuildCurveExpress(List<CurvePoint> points, eFitType fitType)
|
{
|
if (points == null || !points.Any())
|
{
|
return default;
|
}
|
switch (fitType)
|
{
|
case eFitType.ThroughPoint: return TwinRelateCurve0.BuildCurveExpress(points);
|
case eFitType.LinearCurve: return TwinRelateCurve1.BuildCurveExpress(points);
|
case eFitType.ConicCurveB0: return TwinRelateCurve2B0.BuildCurveExpress(points);
|
case eFitType.ConicCurve: return TwinRelateCurve2M.BuildCurveExpress(points);
|
case eFitType.CubicCurve: return TwinRelateCurve3M.BuildCurveExpress(points);
|
case eFitType.FourM: return TwinRelateCurve4M.BuildCurveExpress(points);
|
default: return default;
|
}
|
}
|
|
}
|
}
|