, Visual C#


         

z ,


Result = new float[5] { 0, 0, 0, 0, 0 };
for (i = 1; i <= 4; i++)
{
value = 0;
for (j = 1; j <= 4; j++)
{
value = value + V[j] * M[j, i];
}
Result[i] = value;
}
// (value = Result[4]):
if (value != 0)
{
Result[1] = Result[1] / value;
Result[2] = Result[2] / value;
}
else
{
// z - .
// z , ,
// :
Result[3] = Single.MaxValue;
}
Result[4] = 1;
}
// :
public void MatrixApply(ref float[] V,
ref float[,] M, ref float[] Result)
{
Result[1] = V[1] * M[1, 1] + V[2] * M[2, 1] +
V[3] * M[3, 1] + M[4, 1];
Result[2] = V[1] * M[1, 2] + V[2] * M[2, 2] +
V[3] * M[3, 2] + M[4, 2];
Result[3] = V[1] * M[1, 3] + V[2] * M[2, 3] +
V[3] * M[3, 3] + M[4, 3];
Result[4] = 1;
}
// .
// 0, 0, 0, 1 :
public void m3MatMultiplyFull(ref float[,] Result,
ref float[,] A, ref float[,] B)
{
int i, j, k; float value; Result = new float[5, 5];
for (i = 1; i <= 4; i++)
{
for (j = 1; j <= 4; j++)
{
value = 0;
for (k = 1; k <= 4; k++)
value = value + A[i, k] * B[k, j];
Result[i, j] = value;
}
}
}
// :
public void m3MatMultiply(ref float[,] Result,
ref float[,] A, ref float[,] B)
{
Result[1, 1] = A[1, 1] * B[1, 1] + A[1, 2] * B[2, 1]
+ A[1, 3] * B[3, 1];
Result[1, 2] = A[1, 1] * B[1, 2] + A[1, 2] * B[2, 2]
+ A[1, 3] * B[3, 2];
Result[1, 3] = A[1, 1] * B[1, 3] + A[1, 2] * B[2, 3]
+ A[1, 3] * B[3, 3];
Result[1, 4] = 0;
Result[2, 1] = A[2, 1] * B[1, 1] + A[2, 2] * B[2, 1]
+ A[2, 3] * B[3, 1];

    





Forekc.ru
, , , , , , , , , ,