阅读 134

AutoCAD.NET:矩阵和变换–矩阵信息

[CommandMethod("Matrix_PrintOut")]
public static void Matrix_PrintOut()
{
    Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
    Database db = HostApplicationServices.WorkingDatabase;
    try
    {
        Matrix3d identityMatrix = Matrix3d.Identity; //单位矩阵
        ed.WriteMessage("\nThe identity matrix is: \n{0}\n", identityMatrix );
 
        Plane plane = new Plane(new Point3d(10, 0, 0), new Vector3d(1, 1, 1));
        Point3d point1 = new Point3d(5, 3, 1);
        Point3d point2 = new Point3d(10, 20, 30);
        Vector3d normal = new Vector3d(1, 2, 3);
        Vector3d vector = new Vector3d(10, 10, 10);
        //移动矩阵
        Matrix3d movementMatrix = Matrix3d.Displacement(vector);
        ed.WriteMessage("\nThe movement matrix is: \n{0}\n", movementMatrix);
        //旋转矩阵
Matrix3d rotationMatrix
= Matrix3d.Rotation(Math.PI / 4, Vector3d.ZAxis, point1); ed.WriteMessage("\nThe rotation matrix is: \n{0}\n", rotationMatrix); //绕原点缩放矩阵
Matrix3d scaleAroundOriginMatrix
= Matrix3d.Scaling(2, Point3d.Origin); ed.WriteMessage("\nThe scaleAroundOrigin matrix is: \n{0}\n", scaleAroundOriginMatrix); //绕点pt1旋转矩阵
Matrix3d scaleAroundPointMatrix
= Matrix3d.Scaling(2, point1); ed.WriteMessage("\nThe scaleAroundPoint matrix is: \n{0}\n", scaleAroundPointMatrix); //点镜像矩阵
Matrix3d pointMirrorMatrix
= Matrix3d.Mirroring(point1); ed.WriteMessage("\nThe pointMirror matrix is: \n{0}\n", pointMirrorMatrix); //线镜像矩阵
Matrix3d lineMirrorMatrix
= Matrix3d.Mirroring(new Line3d(point1, point2)); ed.WriteMessage("\nThe lineMirror matrix is: \n{0}\n", lineMirrorMatrix); //面镜像矩阵
Matrix3d planeMirrorMatrix
= Matrix3d.Mirroring(plane); ed.WriteMessage("\nThe planeMirror matrix is: \n{0}\n", planeMirrorMatrix); //复合矩阵
Matrix3d compondMatrix
= movementMatrix.PostMultiplyBy(rotationMatrix) .PostMultiplyBy(scaleAroundPointMatrix) .PostMultiplyBy(lineMirrorMatrix); ed.WriteMessage("\nThe compond matrix is: \n{0}\n", compondMatrix); //投影矩阵 Matrix3d projectionMatrix = Matrix3d.Projection(plane, normal); ed.WriteMessage("\nThe projection matrix is: \n{0}\n", projectionMatrix);
     Matrix3d planeToWorld1
= Matrix3d.PlaneToWorld(plane); ed.WriteMessage("\nThe planeToWorld1 matrix is: \n{0}\n", planeToWorld1);
     Matrix3d planeToWorld2
= Matrix3d.PlaneToWorld(normal); ed.WriteMessage("\nThe planeToWorld2 matrix is: \n{0}\n", planeToWorld2);
     Matrix3d worldToPlane1
= Matrix3d.WorldToPlane(plane); ed.WriteMessage("\nThe worldToPlane1 matrix is: \n{0}\n", worldToPlane1);
    Matrix3d worldToPlane2
= Matrix3d.WorldToPlane(normal); ed.WriteMessage("\nThe worldToPlane2 matrix is: \n{0}\n", worldToPlane2); Matrix3d alignmentCS = Matrix3d.AlignCoordinateSystem( Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, point1, Vector3d.YAxis, Vector3d.ZAxis, Vector3d.XAxis); ed.WriteMessage("\nThe alignmentCS matrix is: \n{0}\n", alignmentCS); } catch (System.Exception ex) { ed.WriteMessage(ex.ToString()); } }

Here is the output:


Command: Matrix_PrintOut

The identity matrix is:
((1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1))

The movement matrix is:
((1,0,0,10),(0,1,0,10),(0,0,1,10),(0,0,0,1))

The rotation matrix is:
((0.707106781186547,-0.707106781186548,0,3.58578643762691),(0.707106781186548,0.
707106781186547,0,-2.65685424949238),(0,0,1,0),(0,0,0,1))

The scaleAroundOrigin matrix is:
((2,0,0,0),(0,2,0,0),(0,0,2,0),(0,0,0,1))

The scaleAroundPoint matrix is:
((2,0,0,-5),(0,2,0,-3),(0,0,2,-1),(0,0,0,1))

The pointMirror matrix is:
((-1,0,0,10),(0,-1,0,6),(0,0,-1,2),(0,0,0,1))

The lineMirror matrix is:
((-0.956709956709957,0.147186147186147,0.251082251082251,9.09090909090909),(0.14
7186147186147,-0.4995670995671,0.853679653679654,2.90909090909091),(0.2510822510
82251,0.853679653679654,0.456277056277056,-3.27272727272727),(0,0,0,1))

The planeMirror matrix is:
((0.333333333333333,-0.666666666666667,-0.666666666666667,6.66666666666667),(-0.
666666666666667,0.333333333333333,-0.666666666666667,6.66666666666667),(-0.66666
6666666667,-0.666666666666667,0.333333333333333,6.66666666666667),(0,0,0,1))

The compond matrix is:
((-1.56114484158069,0.914647213067275,-0.852201419404047,20.9139839881057),(-1.1
4483955049251,-0.498341921979091,1.56236926890742,18.6568542494924),(0.502164502
164502,1.70735930735931,0.912554112554112,2.45454545454545),(0,0,0,1))

The projection matrix is:
((0.833333333333333,-0.166666666666667,-0.166666666666667,1.66666666666667),(-0.
333333333333333,0.666666666666667,-0.333333333333333,3.33333333333333),(-0.5,-0.
5,0.5,5),(0,0,0,1))

The planeToWorld1 matrix is:
((-0.707106781186548,-0.408248290463863,0.577350269189626,10),(0.707106781186548
,-0.408248290463863,0.577350269189626,0),(0,0.816496580927726,0.577350269189626,
0),(0,0,0,1))

The planeToWorld2 matrix is:
((-0.894427190999916,-0.358568582800318,0.267261241912424,0),(0.447213595499958,
-0.717137165600636,0.534522483824849,0),(0,0.597614304667197,0.801783725737273,0
),(0,0,0,1))

The worldToPlane1 matrix is:
((-0.707106781186548,0.707106781186548,0,7.07106781186548),(-0.408248290463863,-
0.408248290463863,0.816496580927726,4.08248290463863),(0.577350269189626,0.57735
0269189626,0.577350269189626,-5.77350269189626),(0,0,0,1))

The worldToPlane2 matrix is:
((-0.894427190999916,0.447213595499958,0,0),(-0.358568582800318,-0.7171371656006
36,0.597614304667197,0),(0.267261241912424,0.534522483824849,0.801783725737273,0
),(0,0,0,1))

The alignmentCS matrix is:
((0,0,1,5),(1,0,0,3),(0,1,0,1),(0,0,0,1))

 

The code and the output here just give some ideas about what kind of transformations (in fact pretty everthing) that the AutoCAD .NET Matrix provides us. In terms of what they really indicate, they will be discussed and demonstrated in coming posts. Please stay tuned.

 provides many project wizards, item wizards, coders and widgets to help automate AutoCAD conveniently and professionally using the AutoCAD .NET API.

If you find the information/code here is helpful, please . Or if you‘d like to make comments to us directly, please feel free to .


原文地址:

 

原文:https://www.cnblogs.com/rf8862/p/15236609.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐