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

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

相关推荐
Young Doro1 天前
从 DV 表示到 MI 下界,再到“置换技巧“(含“指数倾斜“完整推导)
笔记
ACP广源盛139246256731 天前
PCIe Gen3 交换芯片选型笔记:中小通道扩展方案 IX7012@ACP 评估
笔记·硬件架构·硬件工程·pcie·国产芯片
职豚求职小程序刷题1 天前
国投证券笔试测评题型揭秘
笔记
Nuanyt1 天前
LeetCode Hot100 刷题笔记 · 普通数组专题
java·笔记·算法·leetcode
职豚求职小程序1 天前
蒙牛27秋招|数智化未来星测评重点整理✅
笔记
沪上企服通1 天前
从票据到凭证的数据血缘:代账系统的 traceability 与可审计回放设计笔记
笔记
春弦_1 天前
LeetCode Hot 100 刷题笔记
笔记·leetcode·哈希算法
叼烟扛炮1 天前
Linux 学习笔记(四):文件检索与管道重定向
linux·笔记·学习
愤怒火龙果1 天前
蓝队笔记整理04 安全设备、内网处置与云上防护
笔记·网络安全
果壳science1 天前
张祥前最新研究成果登上SCI期刊!
笔记·嵌入式硬件·算法·硬件工程·几何学