csharp中的结构化数组

Structured array in csharp?

本文关键字:数组 结构化 csharp      更新时间:2023-10-16

我有下面的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];