csharp中的结构化数组
Structured array in csharp?
我有下面的C++代码,我想翻译成C#
但我被"元素"的定义所束缚,它是一个结构化数组。
最好使用什么?
var list = new List<KeyValuePair<string, int>>();
for (i = 0; i< 8; i++)
{
Ixx += Element[i].vLocalInertia.x + Element[i].fMass * (Element[i].vCGCoords.y*Element[i].vCGCoords.y + Element[i].vCGCoords.z*Element[i].vCGCoords.z);
Iyy += Element[i].vLocalInertia.y + Element[i].fMass * (Element[i].vCGCoords.z*Element[i].vCGCoords.z + Element[i].vCGCoords.x*Element[i].vCGCoords.x);
Izz += Element[i].vLocalInertia.z + Element[i].fMass * (Element[i].vCGCoords.x*Element[i].vCGCoords.x + Element[i].vCGCoords.y*Element[i].vCGCoords.y);
Ixy += Element[i].fMass * (Element[i].vCGCoords.x * Element[i].vCGCoords.y);
Ixz += Element[i].fMass * (Element[i].vCGCoords.x * Element[i].vCGCoords.z);
Iyz += Element[i].fMass * (Element[i].vCGCoords.y * Element[i].vCGCoords.z);
}
并具有以下类型的结构:
typedef struct _RigidBody {
float fMass; // total mass (constant)
Matrix3x3 mInertia; // mass moment of inertia in body coordinates (constant)
Matrix3x3 mInertiaInverse;// inverse of mass moment of inertia matrix (constant)
Vector vPosition; // position in earth coordinates
Vector vVelocity; // velocity in earth coordinates
Vector vVelocityBody; // velocity in body coordinates
Vector vAngularVelocity;// angular velocity in body coordinates
Vector vEulerAngles; // Euler angles in body coordinates
float fSpeed; // speed (magnitude of the velocity)
Quaternion qOrientation; // orientation in earth coordinates
//Matrix3x3 mRotation; // rotation matrix
Vector vForces; // total force on body
Vector vMoments; // total moment (torque) on body
Matrix3x3 mIeInverse; // inverse of moment of inertia in earth coordinates
} RigidBody, *pRigidBody;
typedef struct _BodyElement {
float fMass;
Vector vDCoords;
Vector vCGCoords;
Vector vLocalInertia;
float fIncidence;
float fDihedral;
Vector vNormal;
float fArea;
int iFlap;
} BodyElement, *pBodyElement;
类似的东西?
public struct Element
{
public struct coord
{
public int x;
public int y;
public int z;
}
public coord vLocalIntetia;
public int fMass;
public coord vCGCoords;
}
Element[] element = new Element[8];
编辑
或者这个(添加您的详细信息)
public struct BodyElement
{
float fMass;
Vector vDCoords;
Vector vCGCoords;
Vector vLocalInertia;
float fIncidence;
float fDihedral;
Vector vNormal;
float fArea;
int iFlap;
}
BodyElement[] element = new BodyElement[8];
相关文章:
- C++使用整数的压缩数组初始化对象
- C++17中函数模板中的静态数组初始化(MSVC 2019)
- 从另一个静态常量数组初始化静态常量数组(只需少量计算)
- 在 Python 和 c++ 2d 数组初始化之间.这是怎麽?为什么呢?
- 字节数组初始化会导致 DirectX 崩溃
- 从函数中全局删除并重新实例化数组结构,而无需在编译时知道数组的大小
- 使用 new 和 值进行数组初始化,但没有显式数量的元素
- 运行时C++数组初始化问题
- 使用带有参数包的数组的成员数组初始化类
- 仅通过C++中数组初始化的不同方法,即可在同一输入上获得两个不同的答案
- C++ 2 个指针数组初始化 C2440
- 如何使用函数的输出初始化 const 数组结构字段?
- C++结构字符数组初始化
- 传递数组结构、ofstream 和 interger 以运行
- 从文本文件中读取并输入到数组结构中,然后显示读取的数据C++
- 如何确定结构数组初始化的大小?
- 结构数组-初始化错误
- 初始化两个不同应用程序的cpp文件共享的headerfile中的数组结构
- 结构或类中的数组初始化
- 在GLSL中从数组初始化结构