csharp中的结构化数组?

时间:2015-02-28 15:15:27

标签: c# c++

我有以下要转换为C#

的C ++代码

但我坚持使用“Element”这个结构化数组的定义。

什么是最好用的?

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;

1 个答案:

答案 0 :(得分:2)

这样的东西?

 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];