deadsy / sdfx

A simple CAD package using signed distance functions
MIT License
518 stars 52 forks source link

obj/screw.go: NPT thread #38

Closed soypat closed 2 years ago

soypat commented 2 years ago

First off, love the project! I'd love to put in some love and right now I'd be needing NPT threads. I've looked at the source in screw.go and have gotten some idea of what's going on though I could use a pointer in how I'd go about adding a new thread. It seems like the problem lies in Screw3D which would need an additional taper parameter, no? Also adding NPT to threadDB.

Also I believe I'd have to modify func (s *ScrewSDF3) Evaluate(p V3) float64. Still having some trouble wrapping my head around the 2D mapping.

NPT threads

deadsy commented 2 years ago

The basic idea of the screw thread stuff is to build a 2d profile of a single tooth of the thread (eg AcmeThread)and then use that as a parameter to Screw3D. That function maps a 3d point onto the 2d profile (spiralling along as it goes), and then works out the distance on the 2d profile.

At the moment there is no taper in that process, the 2d profile does not change as a function of position along the screw. I suppose it could. ie- the height of the 2d profile (distance from the center line of the screw) is itself a function of position along the screw. Casual thinking: Map 3d to 2d. Then alter the y of the 2d based on position along the taper. That seems a bit naive and there's probably a gotcha.

btw- the screw threads don't have a real signed distance function. It's an approximation - and a good one close in to the screw, but at a distance it loses accuracy. That's why it gets rendered using the "Slow" variant of the marching cubes routine.

soypat commented 2 years ago

Thanks for the help! I think I got something working with #39