SldWorks问题 2. 矩阵相关接口使用上的失误

问题

在计算三维点在图纸(DrawingDoc)中的位置时,就是算不对,明明就4、5行代码,怎么看都是很"哇塞"的,毫无问题的。

但结果就是不对。

那就调试一下吧,调试后发现生成的矩阵很不对劲,是个单位矩阵,很奇怪,还什么都不提示!

测试后发现:

IMathUtility类中,CreateTransform方法,传入的数组必须长16

csharp 复制代码
// IMathUtility class.
// Creates a new math transform. 
System.object CreateTransform( 
   System.object ArrayDataIn
)

// Transformation matrix data:
// 
//      | a b c . n |
//      | d e f . o |
//      | g h i . p |
//      | j k l . m |
// 
// The SOLIDWORKS transformation matrix is stored as a homogeneous matrix of 16 elements, ordered as shown. The first 9 elements (a to i) are elements of a 3x3 rotational sub-matrix, the next 3 elements (j, k, l) define a translation vector, and the next 1 element (m) is a scaling factor. The last 3 elements (n, o, p) are unused in this context.
// 
// The 3x3 rotational sub-matrix represents 3 axis sets: 
// 
// row 1 for x-axis components of rotation 
// row 2 for y-axis components of rotation 
// row 3 for z-axis components of rotation 

IMathTransform

问:4x4矩阵本来就是16个元素啊,传长16数组不是很正常吗?

答:当然很正常,但是在这里不太正常。

看看SolidWorks中,矩阵的构成吧,emmm,就一个标准的矩阵。

再看看存储方式,矩阵库,一般都是列优先,少部分是行优先。

这里就不同了,它是0~8存xyz轴旋转,9~11存平移,12存缩放,13~15是不使用的。

MathTransform 可以拿到存储数组,通过属性ArrayData,长16

GetViewXFrom()方法,返回的数组长13,后三个未使用的不返回。然后我下意识就使用这个数组去创建矩阵。

可以传,不报错,结果不对,是个单位矩阵。

相关推荐
Ruannn(努力版)1 小时前
Academic writing
笔记
_Narcissus_1 小时前
链表算法题和静态链表
数据结构·c++·笔记·算法·链表·ai·力扣
九硕智慧建筑一体化厂家2 小时前
大型建筑集群智慧管控升级!IBMS系统实现多系统一体化融合管理
运维·人工智能·笔记·智慧城市
深蓝海拓2 小时前
基于QtPy (PySide6) 的PLC-HMI工程实战记录(五)为当前动作画面的信号连接变量
网络·笔记·python·学习·pyqt
摇滚侠2 小时前
《SpringBoot 3:入门与应用实战》第 6 章 Spring Boot 最佳实践 阅读笔记 10
java·spring boot·笔记
疯狂打码的少年3 小时前
【数据结构】八大排序算法对比总结(时间/空间/稳定性)
数据结构·笔记·算法
selia10783 小时前
AI手撕代码笔记
人工智能·笔记·深度学习
一只旭宝3 小时前
预约系统版本2(pyhton+flask可视化版本)
服务器·数据库·c++·笔记·python·flask
蒲锘3 小时前
DevOps 实验项目笔记三 —— Kubernetes 集群部署阶段
笔记·kubernetes·devops·rbac
米饭不加菜3 小时前
C51 语言参考手册
经验分享·笔记·单片机·嵌入式硬件