在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)

OCC 矩阵变换的更多相关文章

  1. osg矩阵变换节点-----平移旋转缩放

    osg矩阵变换节点-----平移旋转缩放 转自:http://www.cnblogs.com/ylwn817/articles/1973396.html 平移旋转缩放这个三个是osg矩阵操作中,最常见 ...

  2. occ代码分析

    临时变量就是local里面的变量擦除变量就是把模型改成擦除标记 void SelectMgr_SelectionManager::LoadMode (const Handle(SelectMgr_Se ...

  3. OpenGL 矩阵变换

    Overview 几何数据--顶点位置,和标准向量(normal vectors),在OpenGL 管道raterization 处理过程之前可通过顶点操作(Vertex Operation)和基本组 ...

  4. 二维图形的矩阵变换(三)——在WPF中的应用矩阵变换

    原文:二维图形的矩阵变换(三)--在WPF中的应用矩阵变换 UIElement和RenderTransform 首先,我们来看看什么样的对象可以进行变换.在WPF中,用于呈现给用户的对象的基类为Vis ...

  5. 二维图形的矩阵变换(二)——WPF中的矩阵变换基础

    原文:二维图形的矩阵变换(二)--WPF中的矩阵变换基础 在前文二维图形的矩阵变换(一)——基本概念中已经介绍过二维图像矩阵变换的一些基础知识,本文中主要介绍一下如何在WPF中进行矩阵变换. Matr ...

  6. hdu 5671 矩阵变换

    Matrix Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  7. 从UIImage的矩阵变换看矩阵运算的原理

    1.矩阵的基本知识: struct CGAffineTransform {  CGFloat a, b, c, d;  CGFloat tx, ty;}; CGAffineTransform CGAf ...

  8. VS2012下基于Glut 矩阵变换示例程序:

    也可以使用我们自己的矩阵运算来实现OpenGL下的glTranslatef相应的旋转变换.需要注意的是OpenGL下的矩阵是列优先存储的. 示例通过矩阵运算使得圆柱或者甜圈自动绕Y轴旋转,可以单击鼠标 ...

  9. VS2012下基于Glut 矩阵变换示例程序2:

    在VS2012下基于Glut 矩阵变换示例程序:中我们在绘制甜圈或者圆柱时使用矩阵对相应的坐标进行变换后自己绘制甜圈或者圆柱.我们也可以使用glLoadMatrixf.glLoadMatrixd载入变 ...

随机推荐

  1. LinkedList 源码

    1.类继承结构            结构: 2.成员及方法                 注意:其中      getFirst,getLast,removeFirst,removeLast,el ...

  2. ubuntu操作系统的目录结构

    /:根目录,是所有目录的绝对路径的起始点.一般根目录下只存放目录,不要存放文件,/etc./bin./dev./lib./sbin应该和根目录放置在一个分区中 /bin (类似的还有/usr/bin) ...

  3. 【Hexo】deploy出错的解决方法

    .ERROR Deployer not found: git 执行npm install hexo-deployer-git --save .$ hexo d INFO Deploying: git ...

  4. 利用node、express初始化项目

    前端做整站是开发,例如:前端是用了vue创建初始化项目,后端我们不会php.java等,我们只能用node去创建去做后端代码,本文就给大家讲解最基础的从零开始创建一个项目的后端环境. 一般来说前后端代 ...

  5. 团体程序设计天梯赛-练习集-L1-041. 寻找250

    L1-041. 寻找250 对方不想和你说话,并向你扔了一串数…… 而你必须从这一串数字中找到“250”这个高大上的感人数字. 输入格式: 输入在一行中给出不知道多少个绝对值不超过1000的整数,其中 ...

  6. DATEADD()

    定义和用法 DATEADD() 函数在日期中添加或减去指定的时间间隔. 语法 DATEADD(datepart,number,date) date 参数是合法的日期表达式.number 是您希望添加的 ...

  7. [luogu1034] 矩形覆盖 (暴力)

    传送门 Description 给n(n<=50)个点(x,y),要求用k(1<=k<=4)个没有联系的矩形覆盖住求矩形最小面积 Solution 感觉不是很可做,结果看TJ后发现数 ...

  8. Oracle 解决表死锁

    select 'alter system kill session ''' || SID || ',' || SERIAL# || ''';' from ( select distinct a.sid ...

  9. 七夕心形demo

    from turtle import * pensize(1) pencolor('red') fillcolor('pink') speed(5) up() goto(-30, 100) down( ...

  10. php如何判断SQL语句的查询结果是否为空?

    PHP与mysql这对黄金搭档配合的相当默契,但偶尔也会遇到一些小需求不知道该怎么做,例如今天要谈到的:如何判断sql语句查询的结果集是否为空! 我们以查询学生信息为例,来看看究竟如何实现我们的需求. ...