namespace Yw.WinFrmUI.Phart
|
{
|
public static class Point2dListExtensions
|
{
|
|
/// <summary>
|
/// 是否完全相同
|
/// </summary>
|
public static bool IsEqualValueX(this List<Yw.Geometry.Point2d> pt_list, List<Yw.Geometry.Point2d> comparer_pt_list)
|
{
|
if (pt_list == null || pt_list.Count() == 0)
|
{
|
if (comparer_pt_list == null || comparer_pt_list.Count() == 0)
|
{
|
return true;
|
}
|
|
return false;
|
}
|
|
if (comparer_pt_list == null || comparer_pt_list.Count() == 0)
|
{
|
if (pt_list == null || pt_list.Count() == 0)
|
{
|
return true;
|
}
|
|
return false;
|
}
|
|
if (pt_list.Count != comparer_pt_list.Count)
|
{
|
return false;
|
}
|
|
for (int i = 0; i < pt_list.Count; i++)
|
{
|
if (Math.Abs(pt_list[i].X - comparer_pt_list[i].X) > 0.001)
|
{
|
return false;
|
}
|
}
|
|
return true;
|
}
|
|
|
/// <summary>
|
/// 修改曲线0点位置的值,曲线值会根据比例逐渐变化,直到fixPtX,不再变化
|
/// </summary>
|
public static List<Yw.Geometry.Point2d> AmendByZeroPointY(this List<Yw.Geometry.Point2d> pt_list, double fix_point_x, double zero_point_y)
|
{
|
if (pt_list == null || pt_list.Count < 3)
|
return null;
|
|
var fit_pt_list = new List<Yw.Geometry.Point2d>();
|
|
//计算差距
|
double zeroDis = pt_list.First().Y - zero_point_y;
|
for (int i = 0; i < pt_list.Count; i++)
|
{
|
double dis = 0;
|
if (pt_list[i].X <= fix_point_x)
|
{
|
dis = zeroDis * (1 - pt_list[i].X / fix_point_x);
|
}
|
else
|
{
|
dis = 0;
|
}
|
|
fit_pt_list.Add(new Yw.Geometry.Point2d(pt_list[i].X, pt_list[i].Y - dis));
|
}
|
|
var cubic_spline = new Yw.Geometry.CubicSpline2d(fit_pt_list);
|
return cubic_spline.GetPointList(pt_list.Count);
|
}
|
|
|
/// <summary>
|
///
|
/// </summary>
|
public static List<Yw.Geometry.Point2d> GetFitPointList(this List<Yw.Geometry.Point2d> pt_list)
|
{
|
if (pt_list==null||!pt_list.Any())
|
return default;
|
|
var cubic_spline = new Yw.Geometry.CubicSpline2d(pt_list);
|
return cubic_spline.GetPointList(pt_list.Count);
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public static List<Yw.Geometry.Point2d> GetFitPointList(this List<Yw.Geometry.Point2d> pt_list, int point_count)
|
{
|
if (pt_list == null || !pt_list.Any())
|
return default;
|
|
var cubic_spline = new Yw.Geometry.CubicSpline2d(pt_list);
|
return cubic_spline.GetPointList(point_count);
|
}
|
|
|
//public static List<Yw.Geometry.Point2d> GetInterPointsX(this List<Yw.Geometry.Point2d> pt_list, double y)
|
//{
|
// if (pt_list == null || pt_list.Count < 2)
|
// {
|
// return default;
|
// }
|
// var list = new List<Yw.Geometry.Point2d>();
|
// for (int i = 0; i < pt_list.Count - 1; i++)
|
// {
|
// if ((y >= pt_list[i].Y && y <= pt_list[i + 1].Y) || (y <= pt_list[i].Y && y >= pt_list[i + 1].Y))
|
// {//直线插值
|
// double x;
|
// if (Math.Abs(pt_list[i].Y - pt_list[i + 1].Y) < 0.01)
|
// x = (pt_list[i].X + pt_list[i + 1].X) * 0.5;
|
// else
|
// x = pt_list[i].X + (pt_list[i + 1].X - pt_list[i].X) * (y - pt_list[i].Y) / (pt_list[i + 1].Y - pt_list[i].Y);
|
|
// list.Add(new Yw.Geometry.Point2d(x, y));
|
// }
|
// }
|
// return list;
|
//}
|
}
|
}
|