本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Single.DenseMatrix.SetRow方法的典型用法代码示例。如果您正苦于以下问题:C# DenseMatrix.SetRow方法的具体用法?C# DenseMatrix.SetRow怎么用?C# DenseMatrix.SetRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MathNet.Numerics.LinearAlgebra.Single.DenseMatrix
的用法示例。
在下文中一共展示了DenseMatrix.SetRow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateRotationFromDirectionVector
/// <summary>
/// Fill this info in
/// </summary>
/// <param name="vDirection">
/// </param>
/// <returns>
/// Fill this info in
/// </returns>
public static IQuaternion GenerateRotationFromDirectionVector(IVector3 vDirection)
{
// Step 1. Setup basis vectors describing the rotation given the input vector and assuming an initial up direction of (0, 1, 0)
Vector3 vDirNormalized = Vector3.Normalize((Vector3)vDirection);
Vector3 vUp = new Vector3(0, 1.0f, 0.0f); // Y Up vector
Vector3 vRight = Vector3.Cross(vUp, vDirNormalized); // The perpendicular vector to Up and Direction
vUp = Vector3.Cross(vDirNormalized, vRight); // The actual up vector given the direction and the right vector
// Step 2. Put the three vectors into the matrix to bulid a basis rotation matrix
// This step isnt necessary, but im adding it because often you would want to convert from matricies to quaternions instead of vectors to quaternions
// If you want to skip this step, you can use the vector values directly in the quaternion setup below
Matrix mBasis = new DenseMatrix(4, 4);
mBasis.SetRow(0, new[] { (float)vRight.x, (float)vRight.y, (float)vRight.z, 0.0f });
mBasis.SetRow(1, new[] { (float)vUp.x, (float)vUp.y, (float)vUp.z, 0.0f });
mBasis.SetRow(2, new[] { (float)vDirNormalized.x, (float)vDirNormalized.y, (float)vDirNormalized.z, 0.0f });
mBasis.SetRow(3, new[] { 0.0f, 0.0f, 0.0f, 1.0f });
// Step 3. Build a quaternion from the matrix
double dfWScale = Math.Sqrt(1.0f + mBasis.At(0, 0) + mBasis.At(1, 1) + mBasis.At(2, 2)) / 2.0f * 4.0;
if (dfWScale == 0.0)
{
Quaternion q = new Quaternion(0, 1, 0, 0);
return q;
}
Quaternion qrot = new Quaternion(
(float)((mBasis.At(3, 2) - mBasis.At(2, 3)) / dfWScale),
(float)((mBasis.At(0, 2) - mBasis.At(2, 0)) / dfWScale),
(float)((mBasis.At(1, 0) - mBasis.At(0, 1)) / dfWScale),
(float)Math.Sqrt(1.0f + mBasis.At(0, 0) + mBasis.At(1, 1) + mBasis.At(2, 2)) / 2.0f);
var temp = qrot.w;
qrot.w = qrot.y;
qrot.y = temp;
return qrot.Normalize();
}