本文整理汇总了C++中Matrix3::Transposed方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix3::Transposed方法的具体用法?C++ Matrix3::Transposed怎么用?C++ Matrix3::Transposed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix3
的用法示例。
在下文中一共展示了Matrix3::Transposed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Diagonalize
///Diagonalizes a symmetric matrix (M = M^T)
void Diagonalize(Mat3Ptr matrix)
{
if (matrix == NULL)
ErrorIf(matrix == NULL, "Matrix3 - Null pointer passed for matrix.");
Matrix3 quatMatrix = ToMatrix3(CreateDiagonalizer(*matrix));
*matrix = Concat(Concat(quatMatrix, *matrix), quatMatrix.Transposed());
}
示例2: CreateDiagonalizer
Quaternion CreateDiagonalizer(Mat3Param matrix)
{
const unsigned cMaxSteps = 50;
const float cThetaLimit = 1.0e6f;
Quaternion quat(0.0f, 0.0f, 0.0f, 1.0f);
Matrix3 quatMatrix;
Matrix3 diagMatrix;
for(unsigned i = 0; i < cMaxSteps; ++i)
{
ToMatrix3(quat, &quatMatrix);
diagMatrix = Concat(Concat(quatMatrix, matrix), quatMatrix.Transposed());
//Elements not on the diagonal
Vector3 offDiag(diagMatrix(1, 2), diagMatrix(0, 2), diagMatrix(0, 1));
//Magnitude of the off-diagonal elements
Vector3 magDiag = Abs(offDiag);
//Index of the largest element
unsigned k = ((magDiag.x > magDiag.y) && (magDiag.x > magDiag.z)) ? 0 :
((magDiag.y > magDiag.z) ? 1 : 2);
unsigned k1 = (k + 1) % 3;
unsigned k2 = (k + 2) % 3;
//Diagonal already
if(offDiag[k] == 0.0f)
{
break;
}
float theta = (diagMatrix(k2, k2) - diagMatrix(k1, k1)) /
(2.0f * offDiag[k]);
float sign = Math::GetSign(theta);
//Make theta positive
theta *= sign;
//Large term in T
float thetaTerm = theta < 1e6f ? Math::Sqrt(Math::Sq(theta) + 1.0f)
: theta;
//Sign(T) / (|T| + sqrt(T^2 + 1))
float t = sign / (theta + thetaTerm);
//c = 1 / (t^2 + 1) t = s / c
float c = 1.0f / Math::Sqrt(Math::Sq(t) + 1.0f);
//No room for improvement - reached machine precision.
if(c == 1.0f)
{
break;
}
//Jacobi rotation for this iteration
Quaternion jacobi(0.0f, 0.0f, 0.0f, 0.0f);
//Using 1/2 angle identity sin(a/2) = sqrt((1-cos(a))/2)
jacobi[k] = sign * Math::Sqrt((1.0f - c) / 2.0f);
//Since our quat-to-matrix convention was for v*M instead of M*v
jacobi.w = Math::Sqrt(1.0f - Math::Sq(jacobi[k]));
//Reached limits of floating point precision
if(jacobi.w == 1.0f)
{
break;
}
quat *= jacobi;
Normalize(&quat);
}
return quat;
}