John | 曲

Reflection in Transition

贝贝60秒:为啥重造这轮子

曲政 / 2019-09-10


今天是贝贝报告给你的第 194 天
2019-09-10 星期二

今天用 FreeCAD 的 Assembly3 模块,做机构原理图。发现它现有的功能,无法满足我的需求,于是想借用原代码中的解算器部分。读原代码的安装说明,末尾有这样一段话,给我一些感触。

SolveSpace

SolveSpace is by itself a standalone CAD software with excellent assembly support. IMO, it has the opposite design principle of FreeCAD, which is big, modular, and fully extensible. SolveSpace, on the other hand is lean and compact, and does extremely well for what it offers. But, you most likely will find something you want that's missing, and have to seek out other software for help. The constraint solver of SolveSpace is available as a small library for integration by third party software, which gives us the opportunity to bring the best from both worlds.

SymPy + SciPy

The other constraint solver backend uses SymPy and SciPy. They are mostly Python based, with some native acceleration in certain critical parts. The backend implementation models after SolveSpace's solver design, that is, symbolic algebraic + non-linear least square minimization. It can be considered as a python implementation of the SolveSpace's solver.

SciPy offers a dozen of different minimization algorithms, but most of which cannot compete with SolveSpace performance wise. The following list shows some non-formal testing result using default parameters with the sample assembly described later

The reasons for writing this backend are,

SolveSpace 做得很好,已经够用,也成功移植过来了。但是开发者为什么要用 python 重新实现一遍呢?作者解释说,第一是许可协议可能不合;第二是为了学习,深刻理解之后才能做进一步的试验;第三是为了将来的功能扩展。

作者想造的是屹立百年的海湾大桥,不能只着眼于“够用就好”。重造轮子有必要。

另:翻看代码,我发觉我要的不是“约束”的算法,而是要机械机构的位置速度分析。虽然看起来做出的是同一个东西,然而它们是两码事。

img