初学C#,关于函数变换部分,导出的数据与实际数据不符
namespace streamread
{
class Program
{
private static readonly double resolution = 0.36;
private static readonly double step_half = 384;
private static readonly double sensor_height = 1000;
const double SamplingTime = 0.1;
const double RunningTime = 38;
const int GET_NUM = (int)(RunningTime / SamplingTime);
static void Main(string[] args)
{
var sr = new StreamReader(path: @"C:\Users\Desktop\Distances.csv");
int index = 0;
double[,] coordinateX = new double[768,380];
double[,] coordinateY = new double[768,380];
double[,] coordinateZ = new double[768,380];
while (sr.Peek() != -1)
{
for (int i= 0; i< 768; i++)
{
var line = sr.ReadLine().Split(',');
for (int j = 0; j < 380; j++)
{
var distances = Convert.ToDouble(line[j]);
if (distances <= 200)
{
distances = 0;
}
var angle = Index2Angle(index);
var rad = angle / 180 * Math.PI;
if (j <= 33)
{
coordinateZ[i,j] = 0;
coordinateX[i, j] = distances * Math.Sin(rad);
}
else if (j <= 78)
{
coordinateZ[i, j] = -20 * (j - 33);
coordinateX[i, j] = distances * Math.Sin(rad);
}
else if (j <= 144)
{
coordinateZ[i, j] = -900;
coordinateX[i, j] = distances * Math.Sin(rad);
}
else if (j <= 159)
{
coordinateZ[i, j] = -900;
coordinateX[i, j] = distances * Math.Sin(rad) + 20 * (j - 144);
}
else if (j <= 224)
{
coordinateZ[i, j] = -900;
coordinateX[i, j] = distances * Math.Sin(rad) + 300;
}
else if (j <= 269)
{
coordinateZ[i, j] = -900 + 20 * (j - 224);
coordinateX[i, j] = distances * Math.Sin(rad) + 300;
}
else if (j <= 335)
{
coordinateZ[i, j] = 0;
coordinateX[i, j] = distances * Math.Sin(rad) + 300;
}
else if (j <= 350)
{
coordinateZ[i, j] = 0;
coordinateX[i, j] = distances * Math.Sin(rad) - 20 * (j - 335);
}
else if (j <= 380)
{
coordinateZ[i, j] = 0;
coordinateX[i, j] = distances * Math.Sin(rad);
}
coordinateY[i,j] = sensor_height + distances * Math.Cos(rad);
}
}
index++;
}
sr.Close();
var sw = new StreamWriter(path: @"C:\Users\Desktop\Distances_xyz.csv");
for (int i = 0; i < 768; i++)
{
for (int j = 0; j < 380; j++)
{
sw.Write(coordinateX[i, j] + "," + coordinateY[i, j] + "," + coordinateZ[i, j] + ",");
sw.WriteLine("");
}
}
sw.Flush();
sw.Close();
Console.WriteLine("complete");
Console.ReadKey();
}
public static double Index2Angle(int index)
{
return (index - step_half) * resolution;
}
}
最后导入的是768x380的二维数组,导出函数变换过后的xyz坐标,为什么y的坐标不符合实际情况,函数的方程式应该没有写错,代码是不是有问题?求各位大佬指点一下