oddtopus / flamingo

FreeCAD - flamingo workbench
GNU Lesser General Public License v3.0
32 stars 13 forks source link

again on accuracy of vectors operation #2

Closed oddtopus closed 6 years ago

oddtopus commented 8 years ago

If you use pypeTools commit nr. 41, the insertion of curves may have failed to find the correct orientation or to trim the pipe ends in some case. This bug has been fixed now and I apologize for that.

Anyway this raise again the issue about the accuracy of floating-point operations applied to Vectors. The reason of the bug was because I used the function DraftVecUtils.rounded() inside functions frameCmd.isParallel() and frameCmd.beamAx() to round-up the inaccuracy (of the order of .e-14) that is introduced in the Placement.Base and Placement.Rotation from some methods such as Rotation.multyply(). This discrepancy, though it is negligible in most of the cases, actually makes the .dot() and .cross() methods uneffective to check parallelism or orthogonality between vectors. Also it probably mess with .Rotation.multVec() method so that orientation of beam's axis results inverted. If anyone could advice for a more sound method to operate with Vectors that can eliminate this bug's nest, please give an hint.

From previous experiences on this matter, this behaviour is caused by the floating point operation itself rather than the program algorithm: it's really easy to generate funny bugs with floating-point arithmetic using either a simple worksheet or a sophisticated numeric algebra software. I think that one way-out from this is to use some kind of symbolic algebra representation of vectors: one possibility for Python is SymPy but I believe that symbolic algebra is already used in some part of the C code of FreeCAD to define the constraints of geometry in sketches. Is it possible to port the related functions written in C to Python? Or even better, is there the possibility to add a symbolic representation in Vector objects and perform rotations and translations symbolically until an actual numeric computation is necessary? In this way, vector operations can be made on their symbolic coordinates, with 100% accuracy, and be evaluated numerically only for representation.

yorikvanhavre commented 8 years ago

This small imprecision is something inherent to opencascade... Everywhere, it works with tolerance values. I can't unfortunately say much about symbolic representation of vectors, I don't know if it exists somewhere in FreeCAD. But if yes, making C++ functionality available to python is very easy.