Skip to content
This repository was archived by the owner on Aug 12, 2024. It is now read-only.

Commit 81f9be4

Browse files
committed
add metric spacer example. change matter package
1 parent 24e22f2 commit 81f9be4

File tree

5 files changed

+98
-8
lines changed

5 files changed

+98
-8
lines changed

examples/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33
Click on image to go to code directory.
44

55

6+
## Metric spacers M3,M4,M6,M8,M16
7+
8+
| Example | Execution Time | File size |
9+
|---|---|---|
10+
|[Metric spacers M3,M4,M6,M8,M16](metric-spacers)|1s|9451kB|
11+
12+
[![Metric spacers M3,M4,M6,M8,M16](fig/metric-spacers.png)](metric-spacers)
13+
14+
615
## ADZ Nagano sensor cover
716

817
| Example | Execution Time | File size |
918
|---|---|---|
10-
|[ADZ Nagano sensor cover](adz-sensor-cover)|1s|10MB|
19+
|[ADZ Nagano sensor cover](adz-sensor-cover)|0.5s|10MB|
1120

1221
[![ADZ Nagano sensor cover](fig/adz-sensor-cover.png)](adz-sensor-cover)
1322

@@ -25,7 +34,7 @@ Click on image to go to code directory.
2534

2635
| Example | Execution Time | File size |
2736
|---|---|---|
28-
|[ATX Bench power supply mod](atx-bench-supply)|1s|4540kB|
37+
|[ATX Bench power supply mod](atx-bench-supply)|0.5s|4540kB|
2938

3039
[![ATX Bench power supply mod](fig/atx-bench-supply.png)](atx-bench-supply)
3140

examples/fig/metric-spacers.png

10.7 KB
Loading

examples/generate_examples.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ var examples = []struct {
3636
ExecutionTime string
3737
}{
3838
// Add new examples here!
39+
{
40+
Name: "Metric spacers M3,M4,M6,M8,M16",
41+
Dir: "metric-spacers",
42+
resultSTL: "spacers.stl",
43+
view: defaultView,
44+
},
3945
{
4046
Name: "ADZ Nagano sensor cover",
4147
Dir: "adz-sensor-cover",

examples/metric-spacers/spacers.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package main
2+
3+
import (
4+
"math"
5+
6+
"github.com/soypat/sdf"
7+
"github.com/soypat/sdf/form3"
8+
"github.com/soypat/sdf/form3/obj3/thread"
9+
"github.com/soypat/sdf/helpers/matter"
10+
"github.com/soypat/sdf/render"
11+
"gonum.org/v1/gonum/spatial/r3"
12+
)
13+
14+
type spacer struct {
15+
// Metric diameter.
16+
D float64
17+
// Height of spacer.
18+
H float64
19+
}
20+
21+
func main() {
22+
spacers := []spacer{
23+
{D: 3, H: 7},
24+
{D: 3, H: 12},
25+
{D: 4, H: 7},
26+
{D: 6, H: 30},
27+
{D: 8, H: 30},
28+
{D: 16, H: 10},
29+
}
30+
var sdfs []sdf.SDF3
31+
var x float64
32+
for i := range spacers {
33+
s, err := spacers[i].sdf(matter.PLA)
34+
if err != nil {
35+
panic(err)
36+
}
37+
s = sdf.Transform3D(s, sdf.Translate3D(r3.Vec{X: x}))
38+
sdfs = append(sdfs, s)
39+
x += spacers[i].D * 3
40+
}
41+
s := sdf.Union3D(sdfs...)
42+
err := render.CreateSTL("spacers.stl", render.NewOctreeRenderer(s, 300))
43+
if err != nil {
44+
panic(err)
45+
}
46+
}
47+
48+
func (s spacer) sdf(material matter.Material) (sdf.SDF3, error) {
49+
const tol = 0.03
50+
holeCorrected := material.InternalDimScale(s.D * (1 + tol))
51+
ftf := math.Ceil(holeCorrected*1.4) - .15 // Face to face hex distance
52+
hexRadius := getHexRadiusFromFTF(ftf)
53+
sp, err := thread.HexHead(hexRadius, s.H, "")
54+
if err != nil {
55+
return nil, err
56+
}
57+
hole, err := form3.Cylinder(s.H, holeCorrected/2, 0)
58+
if err != nil {
59+
return nil, err
60+
}
61+
return sdf.Difference3D(sp, hole), nil
62+
}
63+
64+
func getHexRadiusFromFTF(ftf float64) (radius float64) {
65+
return ftf / math.Cos(30.*math.Pi/180.) / 2
66+
}

helpers/matter/3dprint.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@ package matter
22

33
import "github.com/soypat/sdf"
44

5+
type Material interface {
6+
Scale(s sdf.SDF3) sdf.SDF3
7+
InternalDimScale(real float64) float64
8+
}
9+
510
var (
611
// PLA (polylactic acid) is the most widely used plastic filament material in 3D printing.
7-
PLA = ViscousMaterial{shrink: 0.2e-2, pullShrink: .45} // 0.2% shrinkage
12+
PLA = Viscoelastic{shrink: 0.3e-2, pullShrink: .45} // 0.3% shrinkage
813
)
914

10-
type ViscousMaterial struct {
15+
type Ideal struct{}
16+
17+
func (Ideal) Scale(s sdf.SDF3) sdf.SDF3 { return s }
18+
func (Ideal) InternalDimScale(real float64) float64 { return real }
19+
20+
type Viscoelastic struct {
1121
// shrink is the thermal contraction shrinkage of a material once the material
1222
// cools to room temperature after the heated bed is turned off.
1323
shrink float64
@@ -16,13 +26,12 @@ type ViscousMaterial struct {
1626
}
1727

1828
// Scale scales a 3D
19-
func (m ViscousMaterial) Scale(s sdf.SDF3) sdf.SDF3 {
20-
scale := 1 / (1 - m.shrink) // is this correct?
21-
return sdf.ScaleUniform3D(s, scale)
29+
func (m Viscoelastic) Scale(s sdf.SDF3) sdf.SDF3 {
30+
return sdf.ScaleUniform3D(s, 1+m.shrink)
2231

2332
}
2433

25-
func (m ViscousMaterial) InternalDimScale(real float64) float64 {
34+
func (m Viscoelastic) InternalDimScale(real float64) float64 {
2635
if real <= 0 {
2736
panic("InternalDimScale only works for non-zero dimensions")
2837
}

0 commit comments

Comments
 (0)