- I have a list of Point (coordinates) called profile. Each coordinate point has an X and Y value.
- Now, I want to find the coordinate point with the minimum and maximum Y value. The reason being that I want to calculate the coordinates at the center of the profile.
- Is there shorter way to accomplish this, such as using a lambda function "=>"?
- Here is my code:
public Point FindCenterXY(List<Point> profile)
{
double centerX = profile.First().X + 0.5 * (profile.Last().X - profile.First().X);
List<double> heights = new List<double>();
foreach (var pt in profile)
{
heights.Add(pt.Y);
}
double centerY = heights.Min() + 0.5 * (heights.Max() - heights.Min());
return new Point(centerX, centerY);
}
- Many many thanks in advance to your answers.