/Hardware/DoorHinge.foocad

Parametric hinges.
I printed two pairs for my garden cupboard, one pair in PETG and the other in PLA. Both still work after over a year.
import uk.co.nickthecoder.foocad.screws.v3.*
import static uk.co.nickthecoder.foocad.arrange.v1.Arrange.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.*
include HingeLayingFlat.feather
class DoorHinge : AbstractModel() {
@Custom( about="Diameter of the hinge's outer cylinder" )
var outerD = 10.0
@Custom( about="Diameter of the core inside the hinge" )
var innerD = 6.0
@Custom( about="Length of the hinge" )
var length = 60.0
@Custom( about="Number of pieces on one side of the hinge barrel. Other side has one more" )
var pieces = 2
@Custom( about="Thickness of the hinge plates. Must be less than outerD/2" )
var thickness = 4.0
@Custom( about="Width of the hinge plate" )
var width = 20.0
@Custom( about="Diameter of the hole for the screws" )
var screwD = 4
@Custom( about="Diameter of the countersink hole for the screw head" )
var screwHeadD = 8
@Custom( about="Number of screw holes per plate" )
var holeCount = 3
@Custom( about="Corner rounding radius. 0 for square corners")
var radius = 3
// 0.5 worked fine. Was originally 0.7 (for my old printer).
// 0.3 fused (first layer elephants foot. A knife freed it.
@Custom( about="Distance between moving surfaces" )
var slack = 0.5
fun plate() : Shape2d {
return Square( width-1, length)
.roundCorner(2,radius)
.roundCorner(1,radius)
.centerY()
}
fun countersinks() : Shape3d {
val hole = Countersink( screwD, screwHeadD )
.translateX(outerD/4 + width/2) // Center the holes
.topTo(thickness+0.01)
return hole.repeatY(holeCount, length/holeCount ).centerY()
}
// This could also be used as a template, but I created it because I removed too much
// wood, and wanted to bodge it so that the door closed cleanly :-O
@Piece
fun spacer() : Shape3d {
val plate = (plate() - Square(outerD/2, 100).centerY()).extrude(1)
return plate - countersinks()
}
override fun build() : Shape3d {
val hinge = HingeLayingFlat(outerD, innerD, length, pieces)
hinge.slack = slack
val plate = plate()
.extrude( thickness )
.leftTo(1)
val holes = countersinks()
val plates = (plate - holes).mirrorX().also()
return (hinge and plates)
}
}

