This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add metric spacer example. change matter package
- Loading branch information
Showing
5 changed files
with
98 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
"math" | ||
|
||
"github.com/soypat/sdf" | ||
"github.com/soypat/sdf/form3" | ||
"github.com/soypat/sdf/form3/obj3/thread" | ||
"github.com/soypat/sdf/helpers/matter" | ||
"github.com/soypat/sdf/render" | ||
"gonum.org/v1/gonum/spatial/r3" | ||
) | ||
|
||
type spacer struct { | ||
// Metric diameter. | ||
D float64 | ||
// Height of spacer. | ||
H float64 | ||
} | ||
|
||
func main() { | ||
spacers := []spacer{ | ||
{D: 3, H: 7}, | ||
{D: 3, H: 12}, | ||
{D: 4, H: 7}, | ||
{D: 6, H: 30}, | ||
{D: 8, H: 30}, | ||
{D: 16, H: 10}, | ||
} | ||
var sdfs []sdf.SDF3 | ||
var x float64 | ||
for i := range spacers { | ||
s, err := spacers[i].sdf(matter.PLA) | ||
if err != nil { | ||
panic(err) | ||
} | ||
s = sdf.Transform3D(s, sdf.Translate3D(r3.Vec{X: x})) | ||
sdfs = append(sdfs, s) | ||
x += spacers[i].D * 3 | ||
} | ||
s := sdf.Union3D(sdfs...) | ||
err := render.CreateSTL("spacers.stl", render.NewOctreeRenderer(s, 300)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func (s spacer) sdf(material matter.Material) (sdf.SDF3, error) { | ||
const tol = 0.03 | ||
holeCorrected := material.InternalDimScale(s.D * (1 + tol)) | ||
ftf := math.Ceil(holeCorrected*1.4) - .15 // Face to face hex distance | ||
hexRadius := getHexRadiusFromFTF(ftf) | ||
sp, err := thread.HexHead(hexRadius, s.H, "") | ||
if err != nil { | ||
return nil, err | ||
} | ||
hole, err := form3.Cylinder(s.H, holeCorrected/2, 0) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return sdf.Difference3D(sp, hole), nil | ||
} | ||
|
||
func getHexRadiusFromFTF(ftf float64) (radius float64) { | ||
return ftf / math.Cos(30.*math.Pi/180.) / 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters