Skip to content
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

Add a "height" parameter for rotate_extrude to help with threading #5011

Open
aprotim opened this issue Feb 24, 2024 · 5 comments · May be fixed by #5012
Open

Add a "height" parameter for rotate_extrude to help with threading #5011

aprotim opened this issue Feb 24, 2024 · 5 comments · May be fixed by #5012

Comments

@aprotim
Copy link

aprotim commented Feb 24, 2024

If trying to build threaded parts of any kind in OpenSCAD, there's a persistent frustration that the only in-built method to extrude a shape both vertically and rotationally is to use linear_extrude, which keeps the extruded polygon parallel to the XY plane (more importantly, parallel to the direction of rotation). Ideally, when creating threads (or similar helical structures, like corkscrews, corkscrew marble channels, etc), it would be possible to use 2D geometry to describe the vertical cross-section of the helix and extrude that along a helical path.

Describe the solution you'd like
In a similar way that the twist parameter of linear_extrude extends linear (vertical) extrusion to do rotation as well, an optional height parameter for rotate_extrude could extend rotate extrusion to include vertical translation as well.

Describe alternatives you've considered
Common solutions involve implementing the rotation in OpenSCAD using hull() (which only works with convex cross-sections, or using linear_extrude() as in this user-created library, but these methods are painfully slow, and ad hoc for a function that is useful in many modeling contexts.

Additional context
I have implemented the height parameter in my copy of openscad (PR incoming), and the speedup for spiralizing a semi-complex (non-convex) thread cross-section is 100x in preview mode compared to the linked spiral_extrude library and 200x compared to my home-brewed hull()-based implementation (done by decomposing the cross-section into convex positive shapes and convex negative shapes, and differenceing the hulls). For a full render, the difference is even starker. The C++ implementation finishes in < 0.15s. Both other methods take 10s of minutes. (I'm still waiting for the faster one to finish, it's been at least 20 minutes. I can give actual benchmark numbers later, if required.)

@aprotim
Copy link
Author

aprotim commented Feb 24, 2024

Ah, ok. The spiral_extrude library method ended up with

Total rendering time: 0:33:55.396

Weirdly, my hull-based version which was half as fast in preview rendered twice as fast at 0:16:38.163.

@pca006132
Copy link
Member

Did you try snapshot with manifold?

@pca006132
Copy link
Member

The spiral_extrude library renders in 0.5s when manifold is enabled... don't think it is so slow.

@aprotim
Copy link
Author

aprotim commented Feb 26, 2024

Even with manifold, for a small example (attached as a .txt), spiral_extrude takes about 5x longer to render and has significant noticeable artifacts, whereas rotate_extrude renders precisely the intended geometry (for a given segmentation resolution) at a fraction of the time.

You can use the customizer on the attached script to toggle between spiral_extrude and rotate_extrude with a height parameter, if you apply my patch in your local tree.
screw top w spiral extrude.txt

@aprotim
Copy link
Author

aprotim commented Feb 26, 2024

(BTW, sorry about the failing tests, I'm trying to track down the places where my output differs from expected and patch.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants