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

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

相关推荐
潇冉沐晴4 小时前
div2 1052 个人补题笔记
笔记
蒙奇D索大5 小时前
【计算机网络】[特殊字符] 408高频考点 | 数据链路层组帧:从字符计数到违规编码,一文学透四大实现方法
网络·笔记·学习·计算机网络·考研
njsgcs5 小时前
tekla 使用笔记 切管 分割指定长度的管
笔记·tekla
蒙奇D索大7 小时前
【算法】 递归实战应用:从暴力迭代到快速幂的优化之路
笔记·考研·算法·改行学it
('-')7 小时前
《从根上理解MySQL》第一章学习笔记
笔记·学习·mysql
d111111111d8 小时前
STM32外设学习-串口发送数据-接收数据(笔记)
笔记·stm32·学习
昊喵喵博士9 小时前
直接用 JavaScript 给输入框赋值,Vue 页面input只是纯展示 并 没有触发 vue 的v-model 赋值
笔记
卡提西亚10 小时前
C++笔记-26-类模板
c++·笔记
yaocheng的ai分身11 小时前
停止过度思考 Obsidian:一份真正有效的初学者指南
笔记