计算给定 X Y 系列的本地最大值/最小值
本文关键字:最大值 最小值 系列 计算 | 更新日期: 2023-09-27 18:30:53
>我有一个由Point2D
组成的数组(它有两个成员,x
和y
),例如Point2D[] points
。您可以将此数组视为 X Y 图上的一系列点。数组的排序方式是,它从较小的Point2D.X
排列到较大的Point2D.X
我的问题很简单:您如何找到局部最大值/最小值的点(以及这些点之前和之后的相应项目索引)?回想一下,局部最大值/最小值在数学上定义为 dy/dx=0
。所以我的任务是我需要找到dy/dx=0
的那些点。
请注意,极值点可能位于也可能不位于Point2D
数组内,因为图形是平滑曲线,而不是线性分段折线。极值点可以是数组内两个点的中间点。例如。
是否有任何现有的库/组件已经在 C# 中执行此操作?
这是我的方法:
public class Point2D
{
public double X;
public double Y;
}
public class PointWithIndex
{
// the extreme point where dy/dx=0
public Point2D ExtremePoints;
// the index of the array for the point that locates right before this ExtremePoints
public int PrevItemIndex;
}
public static List<PointWithIndex> FindLocalExtrema(List<Point2D> xyPoints)
{
// the algorithm to find the max/min points of xyPoints
}
我建议在 i
我不确定这是否是你要找的:Catmull-Rom 样条,你可以使用 XNA 框架(在 C# 中)轻松计算,如下所示。
这个想法是:你将使用 Catmull-Rom 迭代或递归地生成点,直到达到局部最大值。