在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. OpenCV中的模板匹配/Filter2d

    1.模板匹配 模板匹配是在图像中寻找目标的方法之一.Come On, Boy.我们一起来看看模板匹配到底是怎么回事. 参考链接:http://www.opencv.org.cn/opencvdoc/2 ...

  2. 揭开jQuery的面纱

    简单地说,jQuery是一个优秀的JavaScript类库,也就是使用JavaScript面向对象的性质编写的一个JavaScript类的集合.jQuery究竟能为我们提供哪些功能呢?简单地说可以从七 ...

  3. React Native - 使用Geolocation进行定位(获取当前位置、监听位置变化)

    1,getCurrentPosition()方法介绍 static getCurrentPosition(geo_success, geo_error?, geo_options? 该方法用于获取当前 ...

  4. Python统计字符串中出现次数最多的人名

    人名最多数统计题目摘自https://python123.io 描述编程模板中给出了一个字符串,其中包含了含有重复的人名,请直接输出出现最多的人名.‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬ ...

  5. eas之MrpUI

    package com.kingdee.eas.custom.mrp.client; import java.awt.Component;import java.awt.event.*;import ...

  6. echarts在地图上绘制散点图(任意点)

    项目需求:在省份地图上绘制散点图,散点位置不一定是哪个城市或哪个区县,即任意点 通过查询官网文档,找到一个与需求类似的Demo:https://www.echartsjs.com/gallery/ed ...

  7. Python学习笔记之类与对象

    这篇文章介绍有关 Python 类中一些常被大家忽略的知识点,帮助大家更全面的掌握 Python 中类的使用技巧 1.与类和对象相关的内置方法 issubclass(class, classinfo) ...

  8. Python学习笔记之函数

    这篇文章介绍有关 Python 函数中一些常被大家忽略的知识点,帮助大家更全面的掌握 Python 中函数的使用技巧 1.函数文档 给函数添加注释,可以在 def 语句后面添加独立字符串,这样的注释被 ...

  9. 百度API的经历,怎样为多个点添加带检索功能的信息窗口

    不管我们要做什么样的效果,APIKey(密钥)都是不可缺少的要件,所以我们需要先去百度申请我们的APIKey!!! 伸手党,请直接到页面底部获取完整代码! 最近做一个门店查询的内容展示,考虑到用户直观 ...

  10. 【习题 4-6 UVA - 508】Morse Mismatches

    [链接] 我是链接,点我呀:) [题意] 给你每个字母对应的摩斯密码. 然后每个单词的莫斯密码由其组成字母的莫斯密码连接而成. 现在给你若干个莫斯密码. 请问你每个莫斯密码对应哪个单词. 如果有多个单 ...