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,后三个未使用的不返回。然后我下意识就使用这个数组去创建矩阵。

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

相关推荐
么么...1 小时前
在 Ubuntu 上安装 Docker 并部署 MySQL 容器
linux·运维·经验分享·笔记·mysql·ubuntu·docker
Asus.Blogs1 小时前
SSE + Resty + Goroutine + Channel 完整学习笔记
笔记·学习·golang
雍凉明月夜1 小时前
深度学习网络笔记Ⅱ(常见网络分类1)
人工智能·笔记·深度学习
卷心菜_1 小时前
代码随想录笔记-背包问题
笔记
北岛寒沫1 小时前
北京大学国家发展研究院 经济学辅修 经济学原理课程笔记(第十三课 垄断竞争)
人工智能·经验分享·笔记
love530love2 小时前
【笔记】Intel oneAPI 开发环境配置
人工智能·windows·笔记·oneapi·onednn·deep neural
HansenPole8252 小时前
元编程笔记
笔记·网络协议·rpc
charlie1145141912 小时前
Git团队协作完全入门指南(上)
笔记·git·学习·教程·工程
im_AMBER4 小时前
Leetcode 85 【滑动窗口(不定长)】最多 K 个重复元素的最长子数组
c++·笔记·学习·算法·leetcode·哈希算法
-suiyuan-4 小时前
sqli-labs靶场3~4笔记
笔记