【问题标题】:How to find the peak 3D coordinate inside a list of 3D coordinates using LINQ?如何使用 LINQ 在 3D 坐标列表中找到峰值 3D 坐标?
【发布时间】:2013-08-12 05:18:34
【问题描述】:
using Microsoft.DirectX.Direct3D;

struct Voxel
{
    public Vector3 p

    public Voxel(float _x, float _y, float _z)
    {
        p = new Vector3(_x, _y, _z);
    }
}

List<Voxel> myDataList = new List<Voxel>();

经过一些添加数据的方法,我终于得到myDataList 有如下内容:

myDataList[0] - { X: 164 , Y: 59 , Z: 120 }
myDataList[1] - { X: 146 , Y: 63 , Z: 120 }
myDataList[2] - { X: 192 , Y: 59 , Z: 120 }
myDataList[3] - { X: 196 , Y: 79 , Z: 120 } //peak coordinate is here
myDataList[4] - { X: 110 , Y: 55 , Z: 120 }

在上面的示例中,myDataList[3] 是其 Y 值最高的峰值坐标,即 79。

我的问题是,如何确定 myDataList[3] 是包含最高 Y 值的峰值坐标?

我知道我可以执行以下操作来获得最大 Y 值

float maxY = myDataList.Max(y => y.p.Y); //output = 79

但我想要的是 3D 坐标 (X, Y, Z) 而不是只知道maxY

*不要按 w.r.t Y 值和.First() 对列表进行降序排序,因为 myDataList 的顺序在我的下一步中确实很重要。

【问题讨论】:

    标签: c# linq 3d directx


    【解决方案1】:

    由于您已经拥有maxY,您可以使用该值来查找最大值Voxel,如下所示

    var maxVoxel = myDataList.FirstOrDefault(x=>x.p.Y ==maxY);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-29
      • 1970-01-01
      • 1970-01-01
      • 2022-11-18
      • 2010-10-12
      相关资源
      最近更新 更多