在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. openMSP430之openmsp430-loader

    openmsp430-loader This simple program allows the user to load the openMSP430 program memory with an ...

  2. jQuery+pjax简单示例汇总

    pjax 是一个jQuery插件,它使用 ajax 和 pushState 来实现快速的浏览体验,包括真正的固定链接,页面标题和工作返回按钮. ajax缺点是破坏了浏览器的前进后退,因为ajax的请求 ...

  3. Polymorphism (computer science)

    In programming languages and type theory, polymorphism (from Greek πολύς, polys, "many, much&qu ...

  4. NYIST 914 Yougth的最大化

    Yougth的最大化时间限制:1000 ms | 内存限制:65535 KB难度:4 描述 Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从中选出k个物品使得单位重量的价值最大吗? ...

  5. DJANGO里让用户自助修改邮箱地址

    因为在部署过程中会涉及用户邮件发送,如果有的同事不愿意收到太多邮件,则可以自己定义为不存在的邮箱. 我们在注册的时候,也不会写用户邮箱地址,那么他们也可以在这里自己更改. changeemail.ht ...

  6. 洛谷——P1095 守望者的逃离

    https://www.luogu.org/problem/show?pid=1095#sub 题目描述 恶魔猎手尤迪安野心勃勃,他背叛了暗夜精灵,率领深藏在海底的娜迦族企图叛变.守望者在与尤迪安的交 ...

  7. J - Assign the task

    J - Assign the task HDU - 3974 思路:一眼秒思路<(* ̄▽ ̄*)/ dfs序+线段树. 通过dfs序把树上问题转化成线段上的问题.然后用线段树解决.    错因:都 ...

  8. Spring MVC-概述(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_overview.htm 说明:示例基于Spring MVC 4.1.6. Spr ...

  9. Spring注解@Repository、@Service、@Controller、@Component

    继前几章所讲解的注解中: http://www.cnblogs.com/EasonJim/p/6892280.html http://www.cnblogs.com/EasonJim/p/689974 ...

  10. 先验概率 vs 后验概率

    其实还不是很懂.看了这篇文章: http://blog.csdn.net/passball/article/details/5859878   事情还没有发生,要求这件事情发生的可能性的大小,是先验概 ...