初学C#,关于函数变换部分,导出的数据与实际数据不符

初学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的坐标不符合实际情况,函数的方程式应该没有写错,代码是不是有问题?求各位大佬指点一下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值