欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > SldWorks问题 2. 矩阵相关接口使用上的失误

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

2024/10/24 4:30:15 来源:https://blog.csdn.net/tzq2821448839/article/details/142785001  浏览:    关键词:SldWorks问题 2. 矩阵相关接口使用上的失误

问题

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

但结果就是不对。

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

测试后发现:

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

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

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com