mauge123 / mechanical-blender

mechanical blender project
Other
70 stars 16 forks source link

increase precision by doing operations on doubles. #25

Open mirlip opened 8 years ago

mirlip commented 8 years ago

Ideal would be to add 64 bit values everywhere. But doing the math operations on 64 bit precision and save the result as 32bit should improve the numerical precision while letting the rest of the code intact. Having it as an option would allow to have a choice between speed and precision for heavy geometry.

mauge123 commented 8 years ago

This is really difficult for existing code, but will be ideal to avoid precision errors in some parts...

mirlip commented 8 years ago

I didn't mean to make all coordinates 64bits, that would be difficult. But this https://developer.blender.org/rB5ea27bec1fc1e65ce85cccd3079883a41970cd6c is an example of how to add double precision to the calculation, without changing the whole data format. It increases precision greatly without coding much and it retains compatibility.

mauge123 commented 8 years ago

I solve the problem using a kind of fixed coma calculation for geometry detect, that could be improved and check for speed issues. Being the input (eg vertices coordinates) stored on floats was also giving problems in some cases. I think this or an aprox to this is much more better than using an error threshold because the results are granted to fixed decimal number precision, so for example a 0.1234567 it's considered equal than 0.124989, as they are stripped both to 0.12. Internally its performing int operations of X * 100

Have you expirement some precision issues ?

mirlip commented 8 years ago

Yes, try to scale a noisy 100 000 vertices mesh to 0 on Z and you will see the problem by looking at the Z value of each vertex. Because it will do the mean of 100 000 of 32 bit floats, precision issues that are in micrometer when done on 2-3 verts become centimeter errors really quickly. It's even worse when you work far away from world origin. If we really want to use Blender to do precision work, at least double computation for all transformation operators (scale, rotate and grab) is required like in the commit I gave above.