FooCAD Source Codeimport uk.co.nickthecoder.foocad.smartextrusion.v1.*
import static uk.co.nickthecoder.foocad.smartextrusion.v1.SmartExtrusion.*
import static uk.co.nickthecoder.foocad.screws.v2.Screws.*
import uk.co.nickthecoder.foocad.smartextrusion.v1.SmartExtrusion
import static uk.co.nickthecoder.foocad.smartextrusion.v1.SmartExtrusion.*
import static uk.co.nickthecoder.foocad.chamferedextrude.v1.ChamferedExtrude.*
class TwistLatch : Model {
@Custom
var latchSize = Vector3( 40, 10, 10 )
@Custom
var latchDiameter = 20
@Custom
var baseSize = Vector3( 30, 50, 4 )
@Custom
var internalRadius = 5
@Custom
val knobRadius = 12
val countersink = Countersink().recess(baseSize.z+1)
fun latchProfile() = Circle( latchDiameter/2 ) +
Square( latchSize.x, latchSize.y )
.centerY()
.roundAllCorners( latchSize.y / 2-1 )
@Piece
fun latch() : Shape3d {
val holeRadius = 3
val profile = latchProfile()
val main = profile.chamferedExtrude( latchSize.z, 2, 1 )
val hole = Circle( holeRadius )
.extrude( latchSize.z + 0.2 )
val forBoltAndSpring = Cylinder( 100, internalRadius )
.bottomTo( latchSize.z )
val base = base().translateZ(-baseSize.z ).previewOnly()
val knob = Circle( knobRadius ).sides(6).roundAllCorners(4).rotate(90)
.smartExtrude(8).scaleBottom(0.8).top( SmartFillet(3) )
.bottomTo(main.top)
val cap = cap().rotateZ(90).mirrorZ().topTo(knob.top+1).previewOnly()
return main + base + knob - hole- forBoltAndSpring + cap
}
@Piece
fun base() : Shape3d {
val profile = Square( baseSize.x, baseSize.y )
.roundAllCorners( 4 )
.center()
val base = profile.extrude( baseSize.z )
val minusProfile = latchProfile().offset(1)
val highStopProfile = (
Square( baseSize.x, baseSize.y )
.center() -
Square( baseSize.x, baseSize.y )
.translate( -latchSize.y / 2 -1, latchSize.y / 2 -1)
)
.roundAllCorners( 4 ) -
minusProfile
val highStop = highStopProfile
.smartExtrude( baseSize.z ).top( Chamfer(1) )
.bottomTo(base.top)
.color("Green")
println("Stop : ${highStop.size.z} vs ${latchSize.z}" )
val lowStop = (profile intersection( Square(60) ) -
minusProfile.rotate(90) -
minusProfile
)
.extrude(2)
.bottomTo(base.top)
.color("Green")
val hole = Cylinder( 100,3).center()
val countersinks = countersink.translateY( (baseSize.y - latchDiameter)/2 + 3)
.mirrorY().also()
.topTo(highStop.top)
.color("Red")
//val lowStop = stopProfile.extrude( 1 ).mirrorY().bottomTo(base.top)
return base + highStop + lowStop - hole - countersinks
}
@Piece
fun cap() : Shape3d {
return Circle( internalRadius + 3 ).sides(6).roundAllCorners(3).extrude(1) +
Cylinder( 6, internalRadius - 0.3 ) -
Cylinder( 6, internalRadius - 1.3 ).translateZ(2)
}
override fun build() = latch()
}