1
1
package threads
2
2
3
3
import (
4
- math "github.com/chewxy/math32"
4
+ "github.com/chewxy/math32"
5
5
"github.com/soypat/glgl/math/ms2"
6
6
"github.com/soypat/gsdf"
7
7
"github.com/soypat/gsdf/glbuild"
8
8
)
9
9
10
+ const (
11
+ sqrt2d2 = math32 .Sqrt2 / 2
12
+ sqrt3 = 1.7320508075688772935274463415058723669428052538103806280558069794
13
+ )
14
+
10
15
// ISO is a standardized thread.
11
16
// Pitch is usually the number following the diameter
12
17
// i.e: for M16x2 the pitch is 2mm
@@ -15,7 +20,8 @@ type ISO struct {
15
20
D float32
16
21
// P is the thread pitch [mm].
17
22
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.
19
25
Ext bool
20
26
}
21
27
@@ -28,14 +34,19 @@ func (iso ISO) ThreadParams() Parameters {
28
34
29
35
func (iso ISO ) Thread () (glbuild.Shader2D , error ) {
30
36
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 )
33
44
rMajor := radius
34
45
r0 := rMajor - (7.0 / 8.0 )* h
35
46
var poly ms2.PolygonBuilder
36
47
if iso .Ext {
37
48
// External threeading.
38
- rRoot := (iso .P / 8.0 ) / math . Cos ( theta )
49
+ rRoot := (iso .P / 8.0 ) / cosTheta
39
50
xOfs := (1.0 / 16.0 ) * iso .P
40
51
poly .AddXY (iso .P , 0 )
41
52
poly .AddXY (iso .P , r0 + h )
@@ -48,7 +59,7 @@ func (iso ISO) Thread() (glbuild.Shader2D, error) {
48
59
} else {
49
60
// Internal threading.
50
61
rMinor := r0 + (1.0 / 4.0 )* h
51
- rCrest := (iso .P / 16.0 ) / math . Cos ( theta )
62
+ rCrest := (iso .P / 16.0 ) / cosTheta
52
63
xOfs := (1.0 / 8.0 ) * iso .P
53
64
poly .AddXY (iso .P , 0 )
54
65
poly .AddXY (iso .P , rMinor )
0 commit comments