Skip to content

Commit f46f2d3

Browse files
committed
update ISO docs and eliminate trig calls
1 parent dacda5f commit f46f2d3

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

forge/threads/iso.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package threads
22

33
import (
4-
math "github.com/chewxy/math32"
4+
"github.com/chewxy/math32"
55
"github.com/soypat/glgl/math/ms2"
66
"github.com/soypat/gsdf"
77
"github.com/soypat/gsdf/glbuild"
88
)
99

10+
const (
11+
sqrt2d2 = math32.Sqrt2 / 2
12+
sqrt3 = 1.7320508075688772935274463415058723669428052538103806280558069794
13+
)
14+
1015
// ISO is a standardized thread.
1116
// Pitch is usually the number following the diameter
1217
// i.e: for M16x2 the pitch is 2mm
@@ -15,7 +20,8 @@ type ISO struct {
1520
D float32
1621
// P is the thread pitch [mm].
1722
P float32
18-
// Is external or internal thread. Ext set to true means external thread.
23+
// Is external or internal thread. Ext set to true means external thread
24+
// which is for screws. Internal threads refer to tapped holes.
1925
Ext bool
2026
}
2127

@@ -28,14 +34,19 @@ func (iso ISO) ThreadParams() Parameters {
2834

2935
func (iso ISO) Thread() (glbuild.Shader2D, error) {
3036
radius := iso.D / 2
31-
theta := 30.0 * math.Pi / 180.
32-
h := iso.P / (2.0 * math.Tan(theta))
37+
// Trig functions for 30 degrees, the thread angle of ISO.
38+
const (
39+
cosTheta = sqrt3 / 2
40+
sinTheta = 0.5
41+
tanTheta = sinTheta / cosTheta
42+
)
43+
h := iso.P / (2.0 * tanTheta)
3344
rMajor := radius
3445
r0 := rMajor - (7.0/8.0)*h
3546
var poly ms2.PolygonBuilder
3647
if iso.Ext {
3748
// External threeading.
38-
rRoot := (iso.P / 8.0) / math.Cos(theta)
49+
rRoot := (iso.P / 8.0) / cosTheta
3950
xOfs := (1.0 / 16.0) * iso.P
4051
poly.AddXY(iso.P, 0)
4152
poly.AddXY(iso.P, r0+h)
@@ -48,7 +59,7 @@ func (iso ISO) Thread() (glbuild.Shader2D, error) {
4859
} else {
4960
// Internal threading.
5061
rMinor := r0 + (1.0/4.0)*h
51-
rCrest := (iso.P / 16.0) / math.Cos(theta)
62+
rCrest := (iso.P / 16.0) / cosTheta
5263
xOfs := (1.0 / 8.0) * iso.P
5364
poly.AddXY(iso.P, 0)
5465
poly.AddXY(iso.P, rMinor)

0 commit comments

Comments
 (0)