本文整理汇总了C#中MatrixD类的典型用法代码示例。如果您正苦于以下问题:C# MatrixD类的具体用法?C# MatrixD怎么用?C# MatrixD使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MatrixD类属于命名空间,在下文中一共展示了MatrixD类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConstructorException2
public void ConstructorException2()
{
MatrixD m = new MatrixD(new double[,] {{ 1, 2 },
{ 3, 4 },
{ 5, 6 }});
new EigenvalueDecompositionD(m);
}
示例2: Test1
public void Test1()
{
MatrixD a = new MatrixD(new double[,] { { 2, -1, 0},
{ -1, 2, -1},
{ 0, -1, 2} });
CholeskyDecompositionD d = new CholeskyDecompositionD(a);
Assert.AreEqual(true, d.IsSymmetricPositiveDefinite);
MatrixD l = d.L;
Assert.AreEqual(0, l[0, 1]);
Assert.AreEqual(0, l[0, 2]);
Assert.AreEqual(0, l[1, 2]);
Assert.IsTrue(MatrixD.AreNumericallyEqual(a, l * l.Transposed));
Assert.IsTrue(MatrixD.AreNumericallyEqual(a, l * l.Transposed));
// Check solving of linear equations.
MatrixD x = new MatrixD(new double[,] { { 1, 2},
{ 3, 4},
{ 5, 6} });
MatrixD b = a * x;
Assert.IsTrue(MatrixD.AreNumericallyEqual(x, d.SolveLinearEquations(b)));
}
示例3: TestRandomA
public void TestRandomA()
{
RandomHelper.Random = new Random(1);
for (int i = 0; i < 100; i++)
{
// Create A.
MatrixD a = new MatrixD(3, 3);
RandomHelper.Random.NextMatrixD(a, 0, 1);
LUDecompositionD d = new LUDecompositionD(a);
if (d.IsNumericallySingular == false)
{
// Check solving of linear equations.
MatrixD b = new MatrixD(3, 2);
RandomHelper.Random.NextMatrixD(b, 0, 1);
MatrixD x = d.SolveLinearEquations(b);
MatrixD b2 = a * x;
Assert.IsTrue(MatrixD.AreNumericallyEqual(b, b2, 0.01));
MatrixD aPermuted = d.L * d.U;
Assert.IsTrue(MatrixD.AreNumericallyEqual(aPermuted, a.GetSubmatrix(d.PivotPermutationVector, 0, 2)));
}
}
}
示例4: TestMatricesWithoutFullRank
public void TestMatricesWithoutFullRank()
{
MatrixD a = new MatrixD(3, 3);
SingularValueDecompositionD svd = new SingularValueDecompositionD(a);
Assert.AreEqual(0, svd.NumericalRank);
Assert.AreEqual(svd.SingularValues[0], svd.Norm2);
double condNumber = svd.ConditionNumber;
a = new MatrixD(new double[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 4, 5, 6 } });
svd = new SingularValueDecompositionD(a);
Assert.AreEqual(2, svd.NumericalRank);
Assert.AreEqual(svd.SingularValues[0], svd.Norm2);
Assert.IsTrue(MatrixD.AreNumericallyEqual(a, svd.U * svd.S * svd.V.Transposed));
svd = new SingularValueDecompositionD(a.Transposed);
Assert.AreEqual(2, svd.NumericalRank);
Assert.IsTrue(MatrixD.AreNumericallyEqual(a.Transposed, svd.U * svd.S * svd.V.Transposed));
Assert.IsTrue(MatrixD.AreNumericallyEqual(a.Transposed, svd.U * svd.S * svd.V.Transposed)); // Repeat to test with cached values.
Assert.AreEqual(svd.SingularValues[0], svd.Norm2);
condNumber = svd.ConditionNumber;
a = new MatrixD(new double[,] { { 1, 2 }, { 1, 2 }, { 1, 2 } });
svd = new SingularValueDecompositionD(a);
Assert.AreEqual(1, svd.NumericalRank);
Assert.IsTrue(MatrixD.AreNumericallyEqual(a, svd.U * svd.S * svd.V.Transposed));
Assert.AreEqual(svd.SingularValues[0], svd.Norm2);
condNumber = svd.ConditionNumber;
}
示例5: MyClipmapHandler
internal MyClipmapHandler(uint id, MyClipmapScaleEnum scaleGroup, MatrixD worldMatrix, Vector3I sizeLod0, RenderFlags additionalFlags)
{
m_clipmapBase = new MyClipmap(id, scaleGroup, worldMatrix, sizeLod0, this);
m_renderFlags = additionalFlags;
MyClipmap.AddToUpdate(MyEnvironment.CameraPosition, m_clipmapBase);
}
示例6: OnWorldPositionChanged
public override void OnWorldPositionChanged(ref MatrixD worldMatrix)
{
var forward = worldMatrix.Forward;
m_origin = worldMatrix.Translation + forward * m_originOffset;
FrontPoint = m_origin + m_rayLength * forward;
Center = (m_origin + FrontPoint) * 0.5f;
}
示例7: MyRenderAtmosphere
public MyRenderAtmosphere(uint id, string debugName, string model, MatrixD worldMatrix, MyMeshDrawTechnique drawTechnique, RenderFlags renderFlags, float atmosphereRadius, float planetRadius, Vector3 atmosphereWavelengths)
: base(id, debugName,model, worldMatrix,drawTechnique, renderFlags)
{
m_atmosphereWavelengths = atmosphereWavelengths;
m_atmosphereRadius = atmosphereRadius;
m_planetRadius = planetRadius;
}
示例8: CreateCell
public IMyClipmapCell CreateCell(MyClipmapScaleEnum scaleGroup, MyCellCoord cellCoord, ref MatrixD worldMatrix)
{
var cell = new MyClipmapCellProxy(cellCoord, ref worldMatrix, m_massiveCenter, m_massiveRadius, m_renderFlags);
cell.SetVisibility(false);
cell.ScaleGroup = scaleGroup;
return cell;
}
示例9: TestToVector
public void TestToVector()
{
var m1 = new MatrixD(new double[] { 1, 2, 3, 4 }, 2, 2);
var v1 = m1.ToVector();
Assert.AreEqual<VectorD>(new VectorD(1, 2, 3, 4), v1);
}
示例10: MyLodMeshMerge
internal MyLodMeshMerge(MyClipmap parentClipmap, int lod, int lodDivisions, ref MatrixD worldMatrix, ref Vector3D massiveCenter, float massiveRadius, RenderFlags renderFlags)
{
Debug.Assert(parentClipmap != null, "Parent clipmap cannot be null");
Debug.Assert(lod >= 0, "Lod level must be non-negative");
Debug.Assert(lodDivisions >= 0, "Invalid number of lod divisions");
m_parentClipmap = parentClipmap;
m_lod = lod;
m_lodDivisions = lodDivisions;
if (m_lodDivisions <= 0)
return;
m_dirtyProxyIndices = new HashSet<int>();
m_cellProxyToAabbProxy = new Dictionary<MyClipmapCellProxy, int>();
m_boundingBoxes = new MyDynamicAABBTreeD(Vector3D.Zero);
int cellCount = lodDivisions*lodDivisions*lodDivisions;
m_mergeJobs = new MergeJobInfo[cellCount];
m_mergedLodMeshProxies = new MyClipmapCellProxy[cellCount];
m_trackedActors = new HashSet<MyActor>[cellCount];
for (int divideIndex = 0; divideIndex < cellCount; ++divideIndex)
{
m_mergedLodMeshProxies[divideIndex] = new MyClipmapCellProxy(new MyCellCoord(Lod, GetCellFromDivideIndex(divideIndex)), ref worldMatrix, massiveCenter, massiveRadius, renderFlags, true);
m_mergeJobs[divideIndex] = new MergeJobInfo { CurrentWorkId = 0, LodMeshesBeingMerged = new List<LodMeshId>(), NextPossibleMergeStartTime = MyCommon.FrameCounter };
m_trackedActors[divideIndex] = new HashSet<MyActor>();
m_dirtyProxyIndices.Add(divideIndex);
}
}
示例11: MyRenderBatch
public MyRenderBatch(uint id, string debugName, MatrixD worldMatrix, RenderFlags renderFlags, List<MyRenderBatchPart> batchParts)
: base(id, debugName, worldMatrix, renderFlags)
{
m_localAABB = BoundingBoxD.CreateInvalid();
m_batchParts.Clear();
m_batchParts.AddList(batchParts);
}
示例12: PrincipalComponentAnalysisD
//--------------------------------------------------------------
/// <summary>
/// Creates the principal component analysis for the given list of points.
/// </summary>
/// <param name="points">
/// The list of data points. All points must have the same
/// <see cref="VectorD.NumberOfElements"/>.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="points"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// <paramref name="points"/> is empty.
/// </exception>
public PrincipalComponentAnalysisD(IList<VectorD> points)
{
if (points == null)
throw new ArgumentNullException("points");
if (points.Count == 0)
throw new ArgumentException("The list of points is empty.");
// Compute covariance matrix.
MatrixD covarianceMatrix = StatisticsHelper.ComputeCovarianceMatrix(points);
// Perform Eigenvalue decomposition.
EigenvalueDecompositionD evd = new EigenvalueDecompositionD(covarianceMatrix);
int numberOfElements = evd.RealEigenvalues.NumberOfElements;
Variances = new VectorD(numberOfElements);
V = new MatrixD(numberOfElements, numberOfElements);
// Sort eigenvalues by decreasing value.
// Since covarianceMatrix is symmetric, we have no imaginary eigenvalues.
for (int i = 0; i < Variances.NumberOfElements; i++)
{
int index = evd.RealEigenvalues.IndexOfLargestElement;
Variances[i] = evd.RealEigenvalues[index];
V.SetColumn(i, evd.V.GetColumn(index));
evd.RealEigenvalues[index] = double.NegativeInfinity;
}
}
示例13: Spawn
public MyEntity Spawn(MyFixedPoint amount, MatrixD worldMatrix, MyEntity owner = null)
{
if (Content is MyObjectBuilder_BlockItem)
{
Debug.Assert(MyFixedPoint.IsIntegral(amount), "Spawning fractional number of grids!");
var blockItem = Content as MyObjectBuilder_BlockItem;
var builder = MyObjectBuilderSerializer.CreateNewObject(typeof(MyObjectBuilder_CubeGrid)) as MyObjectBuilder_CubeGrid;
builder.GridSizeEnum = MyCubeSize.Small;
builder.IsStatic = false;
builder.PersistentFlags |= MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.Enabled;
builder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix);
var block = MyObjectBuilderSerializer.CreateNewObject(blockItem.BlockDefId) as MyObjectBuilder_CubeBlock;
builder.CubeBlocks.Add(block);
MyCubeGrid firstGrid = null;
for (int i = 0; i < amount; ++i)
{
builder.EntityId = MyEntityIdentifier.AllocateId();
block.EntityId = MyEntityIdentifier.AllocateId();
MyCubeGrid newGrid = MyEntities.CreateFromObjectBuilder(builder) as MyCubeGrid;
firstGrid = firstGrid ?? newGrid;
MyEntities.Add(newGrid);
Sandbox.Game.Multiplayer.MySyncCreate.SendEntityCreated(builder);
}
return firstGrid;
}
else
return MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(amount, Content),worldMatrix, owner != null ? owner.Physics : null);
}
示例14:
void IMyClipmapCell.UpdateWorldMatrix(ref VRageMath.MatrixD worldMatrix, bool sortIntoCullObjects)
{
m_worldMatrix = worldMatrix;
Matrix m = m_worldMatrix * Matrix.CreateScale(m_scale) * Matrix.CreateTranslation(m_translation);
m_actor.SetMatrix(ref m);
}
示例15: DeterminantException
public void DeterminantException()
{
MatrixD a = new MatrixD(new double[,] { { 1, 2 }, { 5, 6 }, { 0, 1 } });
LUDecompositionD d = new LUDecompositionD(a);
double det = d.Determinant;
}