Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/master' into convert_p…
Browse files Browse the repository at this point in the history
…anics_02

- resolves merge conflict in deadsy#27 between panic cleanup (deadsy#24) and API refactor (deadsy#22)
  • Loading branch information
stevegt committed Nov 24, 2020
2 parents 2fb91c2 + 7ab9524 commit 4467e2e
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 79 deletions.
4 changes: 2 additions & 2 deletions examples/axoloti/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var pillarHeight = 16.8
// multiple standoffs
func standoffs() sdf.SDF3 {

k := &sdf.StandoffParms{
k := &obj.StandoffParms{
PillarHeight: pillarHeight,
PillarDiameter: 6.0,
HoleDepth: 10.0,
Expand All @@ -64,7 +64,7 @@ func standoffs() sdf.SDF3 {
{116.0, 10.0, zOfs}, // H8
}

return sdf.Multi3D(sdf.Standoff3D(k), positions)
return sdf.Multi3D(obj.Standoff3D(k), positions)
}

//-----------------------------------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions examples/maixgo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package main
import (
"log"

"github.com/deadsy/sdfx/obj"
. "github.com/deadsy/sdfx/sdf"
)

Expand All @@ -34,7 +35,7 @@ func boardStandoffs() SDF3 {
pillarHeight := 14.0
zOfs := 0.5 * (pillarHeight + baseThickness)
// standoffs with screw holes
k := &StandoffParms{
k := &obj.StandoffParms{
PillarHeight: pillarHeight,
PillarDiameter: 4.5,
HoleDepth: 11.0,
Expand All @@ -54,7 +55,7 @@ func boardStandoffs() SDF3 {
{x0, y0 + y, zOfs},
{x0 + x, y0 + y, zOfs},
}
return Multi3D(Standoff3D(k), positions)
return Multi3D(obj.Standoff3D(k), positions)
}

//-----------------------------------------------------------------------------
Expand All @@ -63,7 +64,7 @@ func bezelStandoffs() SDF3 {
pillarHeight := 22.0
zOfs := 0.5 * (pillarHeight + baseThickness)
// standoffs with screw holes
k := &StandoffParms{
k := &obj.StandoffParms{
PillarHeight: pillarHeight,
PillarDiameter: 6.0,
HoleDepth: 11.0,
Expand All @@ -79,7 +80,7 @@ func bezelStandoffs() SDF3 {
{x0, y0 + y, zOfs},
{x0 + x, y0 + y, zOfs},
}
return Multi3D(Standoff3D(k), positions)
return Multi3D(obj.Standoff3D(k), positions)
}

//-----------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions examples/nordic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func nRF52dkStandoffs() sdf.SDF3 {
zOfs := 0.5 * (pillarHeight + baseThickness)

// standoffs with screw holes
k := &sdf.StandoffParms{
k := &obj.StandoffParms{
PillarHeight: pillarHeight,
PillarDiameter: 6.0,
HoleDepth: 10.0,
Expand All @@ -43,14 +43,14 @@ func nRF52dkStandoffs() sdf.SDF3 {
{2600.0 * sdf.Mil, 500.0 * sdf.Mil, zOfs},
{3800.0 * sdf.Mil, 300.0 * sdf.Mil, zOfs},
}
s0 := sdf.Multi3D(sdf.Standoff3D(k), positions0)
s0 := sdf.Multi3D(obj.Standoff3D(k), positions0)

// standoffs with support stubs
k.HoleDepth = -2.0
positions1 := sdf.V3Set{
{600.0 * sdf.Mil, 2200.0 * sdf.Mil, zOfs},
}
s1 := sdf.Multi3D(sdf.Standoff3D(k), positions1)
s1 := sdf.Multi3D(obj.Standoff3D(k), positions1)

return sdf.Union3D(s0, s1)
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func nRF52833dkStandoffs() sdf.SDF3 {
zOfs := 0.5 * (pillarHeight + baseThickness)

// standoffs with screw holes
k := &sdf.StandoffParms{
k := &obj.StandoffParms{
PillarHeight: pillarHeight,
PillarDiameter: 6.0,
HoleDepth: 10.0,
Expand All @@ -113,7 +113,7 @@ func nRF52833dkStandoffs() sdf.SDF3 {
{2600.0 * sdf.Mil, 1600.0 * sdf.Mil, zOfs},
{5050.0 * sdf.Mil, 1825.0 * sdf.Mil, zOfs},
}
s0 := sdf.Multi3D(sdf.Standoff3D(k), positions0)
s0 := sdf.Multi3D(obj.Standoff3D(k), positions0)

// standoffs with support stubs
k.HoleDepth = -2.0
Expand All @@ -122,7 +122,7 @@ func nRF52833dkStandoffs() sdf.SDF3 {
{3550.0 * sdf.Mil, 2200.0 * sdf.Mil, zOfs},
{3800.0 * sdf.Mil, 300.0 * sdf.Mil, zOfs},
}
s1 := sdf.Multi3D(sdf.Standoff3D(k), positions1)
s1 := sdf.Multi3D(obj.Standoff3D(k), positions1)

return sdf.Union3D(s0, s1)
}
Expand Down
79 changes: 79 additions & 0 deletions obj/standoff.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//-----------------------------------------------------------------------------
/*
PCB Standoffs, Mounting Pillars
*/
//-----------------------------------------------------------------------------

package obj

import "github.com/deadsy/sdfx/sdf"

//-----------------------------------------------------------------------------

// StandoffParms defines the parameters for a board standoff pillar.
type StandoffParms struct {
PillarHeight float64
PillarDiameter float64
HoleDepth float64 // > 0 is a hole, < 0 is a support stub
HoleDiameter float64
NumberWebs int // number of triangular gussets around the standoff base
WebHeight float64
WebDiameter float64
WebWidth float64
}

// pillarWeb returns a single pillar web
func pillarWeb(k *StandoffParms) sdf.SDF3 {
w := sdf.NewPolygon()
w.Add(0, 0)
w.Add(0.5*k.WebDiameter, 0)
w.Add(0, k.WebHeight)
s := sdf.Extrude3D(sdf.Polygon2D(w.Vertices()), k.WebWidth)
m := sdf.Translate3d(sdf.V3{0, 0, -0.5 * k.PillarHeight}).Mul(sdf.RotateX(sdf.DtoR(90.0)))
return sdf.Transform3D(s, m)
}

// pillarWebs returns a set of pillar webs
func pillarWebs(k *StandoffParms) sdf.SDF3 {
if k.NumberWebs == 0 {
return nil
}
return sdf.RotateCopy3D(pillarWeb(k), k.NumberWebs)
}

// pillar returns a cylindrical pillar
func pillar(k *StandoffParms) sdf.SDF3 {
return sdf.Cylinder3D(k.PillarHeight, 0.5*k.PillarDiameter, 0)
}

// pillarHole returns a pillar screw hole (or support stub)
func pillarHole(k *StandoffParms) sdf.SDF3 {
if k.HoleDiameter == 0.0 || k.HoleDepth == 0.0 {
return nil
}
s := sdf.Cylinder3D(sdf.Abs(k.HoleDepth), 0.5*k.HoleDiameter, 0)
zOfs := 0.5 * (k.PillarHeight - k.HoleDepth)
return sdf.Transform3D(s, sdf.Translate3d(sdf.V3{0, 0, zOfs}))
}

// Standoff3D returns a single board standoff.
func Standoff3D(k *StandoffParms) sdf.SDF3 {
s0 := sdf.Union3D(pillar(k), pillarWebs(k))
if k.NumberWebs != 0 {
// Cut off any part of the webs that protrude from the top of the pillar
s0 = sdf.Intersect3D(s0, sdf.Cylinder3D(k.PillarHeight, k.WebDiameter, 0))
}
// Add the pillar hole/stub
if k.HoleDepth >= 0.0 {
// hole
s0 = sdf.Difference3D(s0, pillarHole(k))
} else {
// support stub
s0 = sdf.Union3D(s0, pillarHole(k))
}
return s0
}

//-----------------------------------------------------------------------------
67 changes: 0 additions & 67 deletions sdf/shapes3.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,73 +175,6 @@ func Washer3D(k *WasherParms) (SDF3, error) {
return s, nil
}

//-----------------------------------------------------------------------------
// Board standoffs

// StandoffParms defines the parameters for a board standoff pillar.
type StandoffParms struct {
PillarHeight float64
PillarDiameter float64
HoleDepth float64 // > 0 is a hole, < 0 is a support stub
HoleDiameter float64
NumberWebs int // number of triangular gussets around the standoff base
WebHeight float64
WebDiameter float64
WebWidth float64
}

// single web
func pillarWeb(k *StandoffParms) SDF3 {
w := NewPolygon()
w.Add(0, 0)
w.Add(0.5*k.WebDiameter, 0)
w.Add(0, k.WebHeight)
s := Extrude3D(Polygon2D(w.Vertices()), k.WebWidth)
m := Translate3d(V3{0, 0, -0.5 * k.PillarHeight}).Mul(RotateX(DtoR(90.0)))
return Transform3D(s, m)
}

// multiple webs
func pillarWebs(k *StandoffParms) SDF3 {
if k.NumberWebs == 0 {
return nil
}
return RotateCopy3D(pillarWeb(k), k.NumberWebs)
}

// pillar
func pillar(k *StandoffParms) SDF3 {
return Cylinder3D(k.PillarHeight, 0.5*k.PillarDiameter, 0)
}

// pillar hole
func pillarHole(k *StandoffParms) SDF3 {
if k.HoleDiameter == 0.0 || k.HoleDepth == 0.0 {
return nil
}
s := Cylinder3D(Abs(k.HoleDepth), 0.5*k.HoleDiameter, 0)
zOfs := 0.5 * (k.PillarHeight - k.HoleDepth)
return Transform3D(s, Translate3d(V3{0, 0, zOfs}))
}

// Standoff3D returns a single board standoff.
func Standoff3D(k *StandoffParms) SDF3 {
s0 := Union3D(pillar(k), pillarWebs(k))
if k.NumberWebs != 0 {
// Cut off any part of the webs that protrude from the top of the pillar
s0 = Intersect3D(s0, Cylinder3D(k.PillarHeight, k.WebDiameter, 0))
}
// Add the pillar hole/stub
if k.HoleDepth >= 0.0 {
// hole
s0 = Difference3D(s0, pillarHole(k))
} else {
// support stub
s0 = Union3D(s0, pillarHole(k))
}
return s0
}

//-----------------------------------------------------------------------------
// truncated rectangular pyramid (with rounded edges)

Expand Down

0 comments on commit 4467e2e

Please sign in to comment.