-
Notifications
You must be signed in to change notification settings - Fork 520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V2 : 2D union does not create a closed path #534
Comments
It’s a rounding issue introduced by the union function (BSP logic). I’ve seen this before in other reported issues. There’s no way to eliminate the rounding produced by the BSP logic, as there are bound to be side cases of all kinds. The fix is basically ‘snap’ the 2D points to a specific precision. This eliminates all the extra unless precision. Thanks for the test case... I’ll add to the test suite. |
By the way, we could swap ideas on a fix. I have some code as well. |
And in line I haven't shared yet because this is not good code. I am not a JS developer. |
Correct. That’s were the precision must match in toOutlines There are other places in the library where precision also matters. The best solution must produce 2D geometry with perfect precision. I’ll add my solution to a branch so reviews are possible. |
#408 3D precision issues And here’s a hint about the real issue inside the BSP trees. Dirk Gegorius wrote a document about QuickHull. Page 30 (2d) and 77 (3d) have a formula for creating an epsilon value. |
And here’s the issue that led to my solution. jscad/csg.js#15 |
Solved with #535 |
Occurs on current V2 branch, please label V2.
Given the following example:
And rendering it with cli:
node cli.js test.js -of svg -o test.svg
Produced the following error:
I would expect the following image rendering:
However, OpenJSCAD is not able to render this correctly, since... well the path is not closed...
Let me explain:
We are combining a circle and a rectangle by a union operation. The circle has a segment count of 4 which ultimately degenerates it to a diamond. However, the coordinates of this diamond are due to construction from sin/cos functions not perfect. The corner points would be ideally [2,0], [0,2],[-2,0],[0,-2], but due to floating point arithmetic and sin/cos we get something like e.g. 1.2246468525851679e-16 for 0.
In general this is totally expected and no problem as these numbers are essentially zero.
However, when the outline of this union shape is computed the edge of the rectangle and the circle do not perfectly meet. The rectangle hits [2,0] perfectly and the circle hits say [2, 0.000000001].
In
packages/modeling/src/geometry/geom2/toOutlines.js
the algorithm walks around the the union connecting the edges and fails at this critical point. In particular in line 79 when looking up the next edge through the vertex map. This map lookup is obviously based on equality of points, which is not met.Now, in my opinion there are two solutions.
The problem does not occur on 3D geometries, although the 2D case is based on the 3D union operation. We can conclude that it should be possible to improve the reduction of the 3D case to the 2D case somehow that the path turns out to meet perfectly with all edges. (this would be a good solution.
We could change the algorithm to account for an epsilon region around points when walking through the edges. I have implemented this locally and it works, but in my opinion this is a very ugly fix.
Thoughts? Comments?
The text was updated successfully, but these errors were encountered: