zoukankan      html  css  js  c++  java
  • OCC 矩阵变换

    在OpenCADCADE中, 通过gp_Trsf类来进行矩阵变换操作,

    采用矩阵在左的方式: 新点 = 变换矩阵 * 点

    基本原理如下:

    //! Defines a non-persistent transformation in 3D space.
    //! The following transformations are implemented :
    //! . Translation, Rotation, Scale
    //! . Symmetry with respect to a point, a line, a plane.
    //! Complex transformations can be obtained by combining the
    //! previous elementary transformations using the method
    //! Multiply.
    //! The transformations can be represented as follow :
    //!
    //! V1   V2   V3    T       XYZ        XYZ
    //! | a11  a12  a13   a14 |   | x |      | x'|
    //! | a21  a22  a23   a24 |   | y |      | y'|
    //! | a31  a32  a33   a34 |   | z |   =  | z'|
    //! |  0    0    0     1  |   | 1 |      | 1 |
    //!
    //! where {V1, V2, V3} defines the vectorial part of the
    //! transformation and T defines the translation part of the
    //! transformation.
    //! This transformation never change the nature of the objects.

      gp_Trsf定义了单个平移, 旋转, 缩放, 对称等操作

    复杂变换: 需要通过 gp_Trsf乘法来实现, 如:

      一个物体要经过 缩放, 旋转, 平移等一系列操作时, 必须定义为

      平移 * 旋转 * 缩放

    Python示例:

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    
    import math
    from OCC.gp import (gp_Pnt2d, gp_Vec2d, gp_Pnt, gp_Vec,
                        gp_Ax1, gp_OX, gp_OY, gp_OZ,
                        gp_Trsf)
    
    atranslation = gp_Trsf()
    atranslation.SetTranslation(gp_Vec(1, 1, 1))
    
    arotate = gp_Trsf()
    arotate.SetRotation(gp_OZ(), math.pi)
    
    atransform = atranslation * arotate
    
    def test1(): 
        print('测试1, 平移 -> 旋转')
        pt = gp_Pnt(-1, -1, -1)
        print(pt.Coord())
        pt2 = pt.Transform(atranslation)
        print(pt.Coord())
        pt2 = pt.Transform(arotate)
        print(pt.Coord())
    
    
    def test2():
        print('测试2, 平移 * 旋转')
        pt = gp_Pnt(-1, -1, -1)
        print(pt.Coord())
        pt2 = pt.Transform(atranslation * arotate)
        print(pt.Coord())
    
    def test3():
        print('测试3, 旋转 -> 平移')
        pt = gp_Pnt(-1, -1, -1)
        print(pt.Coord())
        pt2 = pt.Transform(arotate)
        print(pt.Coord())
        pt2 = pt.Transform(atranslation)
        print(pt.Coord())
    
    def test4():
        print('测试4, 旋转 * 平移')
        pt = gp_Pnt(-1, -1, -1)
        print(pt.Coord())
        pt2 = pt.Transform(arotate * atranslation)
        print(pt.Coord())
    
    
    if __name__ == '__main__':
        test1()
        test2()
        test3()
        test4()
    输出结果为:
    测试1, 平移 -> 旋转 (-1.0, -1.0, -1.0) (0.0, 0.0, 0.0) (0.0, 0.0, 0.0) 测试2, 平移 * 旋转 (-1.0, -1.0, -1.0) (2.0, 2.0, 0.0) 测试3, 旋转 -> 平移 (-1.0, -1.0, -1.0) (1.0000000000000002, 0.9999999999999999, -1.0) (2.0, 2.0, 0.0) 测试4, 旋转 * 平移 (-1.0, -1.0, -1.0) (0.0, 0.0, 0.0)
  • 相关阅读:
    hdoj 1002大数加法
    nuxt踩坑
    vue 打包上线后 css3渐变属性丢失的问题解决方案
    linux下crontab不能运行问题
    [转]谈谈数据库的ACID
    web集群时session共享
    redis缓存队列+MySQL +php任务脚本定时批量入库
    Yii2 加载css、js 载静态资源
    PHP实现四种基本排序算法
    phpstorm快捷键
  • 原文地址:https://www.cnblogs.com/yaoyu126/p/6979962.html
Copyright © 2011-2022 走看看