• 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("
    The identity matrix is: 
    {0}
    ", 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("
    The movement matrix is: 
    {0}
    ", movementMatrix);
            //旋转矩阵
    Matrix3d rotationMatrix
    = Matrix3d.Rotation(Math.PI / 4, Vector3d.ZAxis, point1); ed.WriteMessage(" The rotation matrix is: {0} ", rotationMatrix); //绕原点缩放矩阵
    Matrix3d scaleAroundOriginMatrix
    = Matrix3d.Scaling(2, Point3d.Origin); ed.WriteMessage(" The scaleAroundOrigin matrix is: {0} ", scaleAroundOriginMatrix); //绕点pt1旋转矩阵
    Matrix3d scaleAroundPointMatrix
    = Matrix3d.Scaling(2, point1); ed.WriteMessage(" The scaleAroundPoint matrix is: {0} ", scaleAroundPointMatrix); //点镜像矩阵
    Matrix3d pointMirrorMatrix
    = Matrix3d.Mirroring(point1); ed.WriteMessage(" The pointMirror matrix is: {0} ", pointMirrorMatrix); //线镜像矩阵
    Matrix3d lineMirrorMatrix
    = Matrix3d.Mirroring(new Line3d(point1, point2)); ed.WriteMessage(" The lineMirror matrix is: {0} ", lineMirrorMatrix); //面镜像矩阵
    Matrix3d planeMirrorMatrix
    = Matrix3d.Mirroring(plane); ed.WriteMessage(" The planeMirror matrix is: {0} ", planeMirrorMatrix); //复合矩阵
    Matrix3d compondMatrix
    = movementMatrix.PostMultiplyBy(rotationMatrix) .PostMultiplyBy(scaleAroundPointMatrix) .PostMultiplyBy(lineMirrorMatrix); ed.WriteMessage(" The compond matrix is: {0} ", compondMatrix); //投影矩阵 Matrix3d projectionMatrix = Matrix3d.Projection(plane, normal); ed.WriteMessage(" The projection matrix is: {0} ", projectionMatrix);
         Matrix3d planeToWorld1
    = Matrix3d.PlaneToWorld(plane); ed.WriteMessage(" The planeToWorld1 matrix is: {0} ", planeToWorld1);
         Matrix3d planeToWorld2
    = Matrix3d.PlaneToWorld(normal); ed.WriteMessage(" The planeToWorld2 matrix is: {0} ", planeToWorld2);
         Matrix3d worldToPlane1
    = Matrix3d.WorldToPlane(plane); ed.WriteMessage(" The worldToPlane1 matrix is: {0} ", worldToPlane1);
        Matrix3d worldToPlane2
    = Matrix3d.WorldToPlane(normal); ed.WriteMessage(" The worldToPlane2 matrix is: {0} ", worldToPlane2); Matrix3d alignmentCS = Matrix3d.AlignCoordinateSystem( Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, point1, Vector3d.YAxis, Vector3d.ZAxis, Vector3d.XAxis); ed.WriteMessage(" The alignmentCS matrix is: {0} ", 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.

    AutoCAD .NET Addin Wizard (AcadNetAddinWizard) 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 make a kind donation. Or if you'd like to make comments to us directly, please feel free to email us.


    原文地址:AutoCAD .NET: Matrix & Transformations – Matrix Information - AcadNetAddinWizard & More (typepad.com)
  • 相关阅读:
    Python学习笔模式匹配与正则表达式之管理复杂的正则表达式
    Python学习笔模式匹配与正则表达式之组合使用re.IGNORECASE、re.DOTALL和re.VERBOSE
    Python学习笔模式匹配与正则表达式之电话号码和Email地址提取程序
    Python学习笔记模式匹配与正则表达式之findall()方法
    Python学习笔记模式匹配与正则表达式之字符分类
    瀑布流
    CSS就加了一句话就搞定了!
    CSS笔记
    JS
    三层架构笔记
  • 原文地址:https://www.cnblogs.com/rf8862/p/15236609.html
Copyright © 2020-2023  润新知