// Barycentric coordinates // ----------------------- // We can find a set of multipliers {m1, m2, m3) of triangle // vertices {V1, V2, V3} such that any point P in the plane // can be represented as m1V1 + m2V2 + m3V3. With the addition // of normalization constraint m1 + m2 + m3 = 1, we can write // this as: // // Px | v1x v2x v3x | m1 // Py = | v1y v2y v3y | * m2 // 1 | 1 1 1 | m3 // // The inverse of the |V| matrix depicted above converts real // points into their multipliers. The conversion matricies are // assigned to the tri[] entries here. // static void BarycentricMatrices( vector<triangle> &tri, const vector<vertex> &ctl, FILE* flog ) { int ntri = tri.size(); for( int k = 0; k < ntri; ++k ) { triangle& T = tri[k]; vertex v0 = ctl[T.v[0]], v1 = ctl[T.v[1]], v2 = ctl[T.v[2]]; double a[3][3]; fprintf( flog, "Tri: (%d %d) (%d %d) (%d %d).\n", v0.x, v0.y, v1.x, v1.y, v2.x, v2.y ); a[0][0] = v0.x; a[0][1] = v1.x; a[0][2] = v2.x; a[1][0] = v0.y; a[1][1] = v1.y; a[1][2] = v2.y; a[2][0] = 1.0; a[2][1] = 1.0; a[2][2] = 1.0; Invert3x3Matrix( T.a, a ); } }
void RigidBody_GeneralTensor::SetInertiaTensor(double inertiaTensorAtRest[9], int updateAngularVelocity) { memcpy(this->inertiaTensorAtRest, inertiaTensorAtRest, sizeof(double) * 9); // compute inverse inertia tensor at rest Invert3x3Matrix(this->inertiaTensorAtRest, inverseInertiaTensorAtRest); inverseInertiaTensorAtRestX = inverseInertiaTensorAtRest[0]; inverseInertiaTensorAtRestY = inverseInertiaTensorAtRest[4]; inverseInertiaTensorAtRestZ = inverseInertiaTensorAtRest[8]; // change the angular velocity accordingly if (updateAngularVelocity) ComputeAngularVelocity(); }