Skip to content

Commit

Permalink
fix taper bug in screw GPU implementation that caused far-out visuals
Browse files Browse the repository at this point in the history
  • Loading branch information
soypat committed Aug 17, 2024
1 parent 42a82f0 commit 7d27200
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion examples/npt-flange/flange.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ func scene() (gleval.SDF3, error) {

pipe, _ := threads.Nut(threads.NutParms{
Thread: npt,
Style: threads.NutKnurl,
Style: threads.NutHex,
})
pipe = gsdf.Scale(pipe, 100)
return makeSDF(pipe)
// Base plate which goes bolted to joint.
flange, _ = gsdf.NewCylinder(flangeD/2, flangeH, flangeH/8)
Expand Down
2 changes: 1 addition & 1 deletion forge/threads/nut.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Nut(k NutParms) (s glbuild.Shader3D, err error) {
return nil, err
}
// internal thread
thread, err := Screw(nh, k.Thread)
thread, err := Screw(nh*(1+1e-2), k.Thread)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion forge/threads/threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ func (s *screw) AppendShaderBody(b []byte) []byte {
b = append(b, `
#define Pi 3.1415926535897932384626433832795
float y = length(p.xy);
if (taper != 0.) { y += p.z * atan(p.x, taper); }
if (taper != 0.) {
y += p.z * atan(taper);
}
float theta = atan(p.y, p.x);
float z = p.z + lead*theta/(2.*Pi);
float sawt = (z + pitch/2.)/pitch;
Expand Down

0 comments on commit 7d27200

Please sign in to comment.