jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.58k stars 505 forks source link

fix(modeling): added fromNoisyPoints() to plane #1322

Closed z3dev closed 4 months ago

z3dev commented 4 months ago

Thanks to @Hermann-SW , the current implement of plane.fromPoints() was found to be very limited, requiring a set of vertices that is both planar and ordered.

See #1321 for the issue.

These changes add a new function to calculate the best-fit plane across any set of vertices. Testing has shown some differences in precision, and fromNoisyPoints() always produces a normal in the positive orientation.

Given that fromPoints() is used internally and produces a directional normal, the new function was created.

All Submissions:

z3dev commented 4 months ago

@platypii What do you think? I was kind of surprised at the current implementation of fromPoints(). It's correct but requires careful positioning of vertices. But in the general sense, a best-fit version is probably better for users.