• String数据转Matrix矩阵


    String数据转Matrix矩阵

    private Matrix String_To_Matrix(string str)

    {

                int[] Remove_Num = new int[10];

                int Remove_Int = 0;

                string Str_One = str;

                //{ {M11:1 M12:0 M13:0 M14:0} {M21:0 M22:1 M23:0 M24:0} {M31:0 M32:0 M33:1 M34:0} {M41:0 M42:0 M43:0 M44:1} }

                //string Str_One = "{ {M11:1 M12:0 M13:0 M14:0} {M21:0 M22:1 M23:0 M24:0} {M31:0 M32:0 M33:1 M34:0} {M41:0 M42:0 M43:0 M44:1} }";

                for (int i = 0; i < Str_One.Length; i++)

                {

                    //string str = Str_One[i].ToString ();

                    if (Str_One[i].Equals('{') || Str_One[i].Equals('}'))

                    {

                        Remove_Num[Remove_Int] = i;

                        Remove_Int += 1;

                    }

                }

                Remove_Int = 0;

                int Remove_num_int = 0;

                string Str_Two = "";// M11:1 M12:0 M13:0 M14:0 M21:0 M22:1 M23:0 M24:0 M31:0 M32:0 M33:1 M34:0 M41:0 M42:0 M43:0 M44:1

                foreach (var item in Remove_Num)

                {

                    //string str = item.ToString();

                    Remove_num_int = item - Remove_Int;

                    Str_Two = Str_One.Remove(Remove_num_int, 1);

                    Str_One = Str_Two;

                    Remove_Int += 1;

                }

                string[] M_int = new string[16];// 1 0 0 0 ,0 1 0 0 ,0 0 1 0 ,0 0 0 1

                for (int i = 0; i < 16; i++)

                {

                    M_int[i] = (Str_Two.Split(' ')[i + 1]).Split(':')[1];

                }

                //Matrix aaaa = new Matrix(0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1);

                Matrix new_Matrix = new Matrix(float.Parse(M_int[0]), float.Parse(M_int[1]), float.Parse(M_int[2]), float.Parse(M_int[3]), float.Parse(M_int[4]), float.Parse(M_int[5]), float.Parse(M_int[6]), float.Parse(M_int[7]), float.Parse(M_int[8]), float.Parse(M_int[9]), float.Parse(M_int[10]), float.Parse(M_int[11]), float.Parse(M_int[12]), float.Parse(M_int[13]), float.Parse(M_int[14]), float.Parse(M_int[15]));

                return new_Matrix;

    }

    注:取Matrix格式string字符串,循环判断添加索引int[]数组,去除‘{}',再根据’  ‘进行对整体string分割取string[],之后依据':'分割读取float于float[]数组,对新建Matrix依次赋值,达到string转matrix效果.....

    支持个人观看使用,如商用或转载,请告知! -----萧朗(QQ:453929789 Email:xiaolang_xl@sina.com)
  • 相关阅读:
    我从来没有想要去
    微信公众号开发系列-发展模式,创建自己的自定义菜单
    iOS6之后 NSAttributedString 福利
    iOS 面试题:OC标题的基本概念&lt;延续&gt;
    逻辑、认识论和本体论“三统一”
    C++中的头文件和源文件
    extern与头文件(*.h)的区别和联系
    Predicate Format String Syntax 与字面量
    编码、格式与网络通信
    充分条件和必要条件的联系和区别是什么
  • 原文地址:https://www.cnblogs.com/XiaoLang0/p/10214056.html
Copyright © 2020-2023  润新知