本文整理汇总了C#中Jitter.LinearMath.JMatrix.Determinant方法的典型用法代码示例。如果您正苦于以下问题:C# JMatrix.Determinant方法的具体用法?C# JMatrix.Determinant怎么用?C# JMatrix.Determinant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jitter.LinearMath.JMatrix
的用法示例。
在下文中一共展示了JMatrix.Determinant方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invert
public static void Invert(ref JMatrix matrix, out JMatrix result)
{
double determinantInverse = 1 / matrix.Determinant();
double m11 = (matrix.M22 * matrix.M33 - matrix.M23 * matrix.M32) * determinantInverse;
double m12 = (matrix.M13 * matrix.M32 - matrix.M33 * matrix.M12) * determinantInverse;
double m13 = (matrix.M12 * matrix.M23 - matrix.M22 * matrix.M13) * determinantInverse;
double m21 = (matrix.M23 * matrix.M31 - matrix.M21 * matrix.M33) * determinantInverse;
double m22 = (matrix.M11 * matrix.M33 - matrix.M13 * matrix.M31) * determinantInverse;
double m23 = (matrix.M13 * matrix.M21 - matrix.M11 * matrix.M23) * determinantInverse;
double m31 = (matrix.M21 * matrix.M32 - matrix.M22 * matrix.M31) * determinantInverse;
double m32 = (matrix.M12 * matrix.M31 - matrix.M11 * matrix.M32) * determinantInverse;
double m33 = (matrix.M11 * matrix.M22 - matrix.M12 * matrix.M21) * determinantInverse;
result.M11 = m11;
result.M12 = m12;
result.M13 = m13;
result.M21 = m21;
result.M22 = m22;
result.M23 = m23;
result.M31 = m31;
result.M32 = m32;
result.M33 = m33;
}
示例2: CalculateMassInertia
public static double CalculateMassInertia(Shape shape, out JVector centerOfMass,
out JMatrix inertia)
{
double mass = 0.0f;
centerOfMass = JVector.Zero; inertia = JMatrix.Zero;
if (shape is Multishape) throw new ArgumentException("Can't calculate inertia of multishapes.", "shape");
// build a triangle hull around the shape
List<JVector> hullTriangles = new List<JVector>();
shape.MakeHull(ref hullTriangles, 3);
// create inertia of tetrahedron with vertices at
// (0,0,0) (1,0,0) (0,1,0) (0,0,1)
double a = 1.0f / 60.0f, b = 1.0f / 120.0f;
JMatrix C = new JMatrix(a, b, b, b, a, b, b, b, a);
for (int i = 0; i < hullTriangles.Count; i += 3)
{
JVector column0 = hullTriangles[i + 0];
JVector column1 = hullTriangles[i + 1];
JVector column2 = hullTriangles[i + 2];
JMatrix A = new JMatrix(column0.X, column1.X, column2.X,
column0.Y, column1.Y, column2.Y,
column0.Z, column1.Z, column2.Z);
double detA = A.Determinant();
// now transform this canonical tetrahedron to the target tetrahedron
// inertia by a linear transformation A
JMatrix tetrahedronInertia = JMatrix.Multiply(A * C * JMatrix.Transpose(A), detA);
JVector tetrahedronCOM = (1.0f / 4.0f) * (hullTriangles[i + 0] + hullTriangles[i + 1] + hullTriangles[i + 2]);
double tetrahedronMass = (1.0f / 6.0f) * detA;
inertia += tetrahedronInertia;
centerOfMass += tetrahedronMass * tetrahedronCOM;
mass += tetrahedronMass;
}
inertia = JMatrix.Multiply(JMatrix.Identity, inertia.Trace()) - inertia;
centerOfMass = centerOfMass * (1.0f / mass);
double x = centerOfMass.X;
double y = centerOfMass.Y;
double z = centerOfMass.Z;
// now translate the inertia by the center of mass
JMatrix t = new JMatrix(
-mass * (y * y + z * z), mass * x * y, mass * x * z,
mass * y * x, -mass * (z * z + x * x), mass * y * z,
mass * z * x, mass * z * y, -mass * (x * x + y * y));
JMatrix.Add(ref inertia, ref t, out inertia);
return mass;
}