using System;
using System.Collections.Generic;
using System.Text;

namespace Generate3DMesh
{
    // Example 17-28. Generating data for the graph

    class GraphDataBuilder
    {
        public static double[,] BuildSincFunction(int xPoints, int yPoints,
                                                  double cycles, double height)
        {
            double[,] points = new double[xPoints, yPoints];
            for (int yIndex = 0; yIndex < yPoints; ++yIndex)
            {
                double y = yIndex; y /= ((yPoints - 1) / 2.0); y -= 1;
                for (int xIndex = 0; xIndex < xPoints; ++xIndex)
                {
                    double x = xIndex; x /= ((xPoints - 1) / 2.0); x -= 1;

                    double d = Math.Sqrt(x * x + y * y) * 2 * Math.PI * cycles;
                    points[xIndex, yIndex] = (d == 0 ? 1 : Math.Sin(d) / d) * height;
                }
            }
            return points;
        }
    }

    // End of Example 17-28.
}
