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)
OCC 矩阵变换的更多相关文章
- osg矩阵变换节点-----平移旋转缩放
osg矩阵变换节点-----平移旋转缩放 转自:http://www.cnblogs.com/ylwn817/articles/1973396.html 平移旋转缩放这个三个是osg矩阵操作中,最常见 ...
- occ代码分析
临时变量就是local里面的变量擦除变量就是把模型改成擦除标记 void SelectMgr_SelectionManager::LoadMode (const Handle(SelectMgr_Se ...
- OpenGL 矩阵变换
Overview 几何数据--顶点位置,和标准向量(normal vectors),在OpenGL 管道raterization 处理过程之前可通过顶点操作(Vertex Operation)和基本组 ...
- 二维图形的矩阵变换(三)——在WPF中的应用矩阵变换
原文:二维图形的矩阵变换(三)--在WPF中的应用矩阵变换 UIElement和RenderTransform 首先,我们来看看什么样的对象可以进行变换.在WPF中,用于呈现给用户的对象的基类为Vis ...
- 二维图形的矩阵变换(二)——WPF中的矩阵变换基础
原文:二维图形的矩阵变换(二)--WPF中的矩阵变换基础 在前文二维图形的矩阵变换(一)——基本概念中已经介绍过二维图像矩阵变换的一些基础知识,本文中主要介绍一下如何在WPF中进行矩阵变换. Matr ...
- hdu 5671 矩阵变换
Matrix Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- 从UIImage的矩阵变换看矩阵运算的原理
1.矩阵的基本知识: struct CGAffineTransform { CGFloat a, b, c, d; CGFloat tx, ty;}; CGAffineTransform CGAf ...
- VS2012下基于Glut 矩阵变换示例程序:
也可以使用我们自己的矩阵运算来实现OpenGL下的glTranslatef相应的旋转变换.需要注意的是OpenGL下的矩阵是列优先存储的. 示例通过矩阵运算使得圆柱或者甜圈自动绕Y轴旋转,可以单击鼠标 ...
- VS2012下基于Glut 矩阵变换示例程序2:
在VS2012下基于Glut 矩阵变换示例程序:中我们在绘制甜圈或者圆柱时使用矩阵对相应的坐标进行变换后自己绘制甜圈或者圆柱.我们也可以使用glLoadMatrixf.glLoadMatrixd载入变 ...
随机推荐
- SAP computer之input and MAR
Input and MAR Below the program counter is the input and MAR block. It includes the address and data ...
- (转)PostGIS+QGIS+GeoServer+OpenLayers实现数据的存储、服务的发布以及地图的显示
http://blog.csdn.net/gisshixisheng/article/details/41575833 标题比较长,主要呢是实现以下几点: 1.将shp数据导入到PostGIS中: 2 ...
- Java 将File转换为MultipartFile类型
首先转换时需要用到commons-fileupload-1.3.2.jar包,若项目中没有就先加入jar包,实现代码如下: 1.根据File创建FileItem import java.io.File ...
- Python 切片 day3
你可以处理列表的部分元素——Python称之为切片 . 一.使用方法: 要创建切片,可指定要使用的第一个元素和最后一个元素的索引. 与函数range() 一样,Python在到达你指定的第二个索引前面 ...
- kvm迁移
一.迁移简介 迁移: 系统的迁移是指把源主机上的操作系统和应用程序移动到目的主机,并且能够在目的主机上正常运行.在没有虚拟机的时代,物理机之间的迁移依靠的是系统备份和恢复技术.在源主机上实时 ...
- composer 安装教程
https://getcomposer.org/download/ 邓士鹏 1.先检查php.ini是否开启ssl ;extension=php_openssl.dll 2. php -r &qu ...
- Luogu P1198 BZOJ 1012 最大数 (线段树)
手动博客搬家: 本文发表于20170821 14:32:05, 原地址https://blog.csdn.net/suncongbo/article/details/77449455 URL: (Lu ...
- DNS绑定多个IP地址
DNS轮循技术 首先介绍一个DNS系统:传统的DNS解析都是一个域名对应一个IP地址,但是通过DNS轮循技术(负载平衡技术)可以做到一个域名对应到多个IP 上. 这样大家难免就会问,这个技术有什么用呢 ...
- [bzoj3209]花神的数论题_数位dp
花神的数论题 bzoj-3209 题目大意:sum(i)表示i的二进制表示中1的个数,求$\prod\limits_{i=1}^n sum(i)$ 注释:$1\le n\le 10^{15}$. 想法 ...
- 日志输出最不重要的就是控制台输出,控制台输出就是system.out而已
1.日志输出最不重要的就是控制台输出,控制台输出就是system.out而已 2.所以日志输出时候会存在一个Bug就是:stdout要配置在日志输出的最前面,因为stdout控制台输出,最不重要,如果 ...