首页 > 解决方案 > 如何在 Dim NormalVectorRotationMatrix As New devDept.Geometry.Matrix 之后将元素添加到矩阵

问题描述

特别是DevDept.Geometry在 VB.Net 应用程序中使用。我创建了一个新矩阵

现在我想用值填充矩阵?任何帮助,将不胜感激。

NormalVectorRotationMatrix在 Visual Studio vb.net 中,创建从类命名的矩阵变量后,devDept.Geometry我键入“ ” ,NormalVectorRotationMatrix.它只显示 4 个方法[]Equals,,,,[]GetHashcode[]GetType[]ToString

我希望看到一个属性/方法列表来定义矩阵的大小,然后看到一个元素列表来填充值。我错过了什么?

Dim NormalVectorRotationMatrix As New devDept.Geometry.Matrix

标签: vb.netmatrixeyeshot

解决方案


如果你想创建一个视野矩阵,这很容易。使用时,您可以通过Transformation类使用它,因此您可以直接跳过Matrix对象并仅使用转换。

Matrix您可能会对eyeshot 中的类不是对象这一事实感到困惑。它实际上是一个辅助类,并且矩阵本身一直只是双数组。

这是您可以使用的 2 种不同类型的矩阵及其工作原理的示例。

// create 2 transformations
var rotation = new devDept.Geometry.Rotation(radian, rotationVector);
var translate = new devDept.Geometry.Translation(x, y, z);

// just a simple object for demonstration purpose
Solid someSolid = Solid.CreateBox(10, 10, 10);

// rotate the solid
someSolid.TransformBy(rotation);

// or translate
someSolid.TransformBy(translate);

// or create a custom transformation (you see the point)
var transformation = rotation * translation * rotation

// apply that custom transformation
someSolid.TransformBy(transformation);

// or even better just create the matrix from scratch
var matrix4x4 = new double[16] {... define 4x4 matrix here ... };

// the transformation object takes a 4x4 double array matrix too
var matrixTransformation = new devDept.Geometry.Transformation(matrix4x4);

如果您使用过System.Media.Media3D.Matrix3Dor .net 然后将该对象正确转换为double[]匹配Eyeshot格式的对象,请使用以下静态方法

public static double[] ToEyeshotMatrix(this Matrix3D matrix)
{
    // this is to format a windows matrix to the proper format eyeshot uses
    return new[]
    {
         matrix.M11,matrix.M21,matrix.M31,matrix.OffsetX,
         matrix.M12,matrix.M22,matrix.M32,matrix.OffsetY,
         matrix.M13,matrix.M23,matrix.M33,matrix.OffsetZ,
         matrix.M14,matrix.M24,matrix.M34,matrix.M44
    };
}

// you can call it like so
var someMatrix = System.Media.Media3D.Matrix3D.Identity;

// apply normal .net transform you would do then
var eyeshotMatrix = new devDept.Geometry.Transformation(someMatrix.ToEyeshotMatrix());

这应该涵盖几乎所有可以在 eyeshot 和 .net 中使用矩阵的方式

作为您对特定矢量操作的评论的更新,您不需要目视。您在System.Windows.Media.Media3D需要添加对PresentationCore程序集的引用的命名空间中拥有它

你做这样的事情

// create some vector to change
var v = new System.Windows.Media.Media3D.Vector3D(1, 0, 0);

// create a matrix to transform our vector
var m = System.Windows.Media.Media3D.Matrix3D.Identity;

// rotate the matrix in Z 90 degree
m.Rotate(new System.Windows.Media.Media3D.Vector3D(0, 0, 1), 90d);

// apply the matrix to the vector
var resultVector = m.Transform(v);

// resultVector is now (0, 1, 0)

推荐阅读