Exit Full View
Up

/Util/DoorHinge.foocad

DoorHinge
FooCAD Source Code
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.*
import static uk.co.nickthecoder.foocad.screws.v1.Screws.*

include HingeLayingFlat.feather

/**
Print Notes

    I've used PLA and PETG for hinges, and both have held up for more than a year.
    
History

    I printed two pairs for my garden cupboard, one pair in PETG and the other in PLA.
    Both still work after over a year.
*/
class DoorHinge : Model {
    
    @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 = 1

    override fun build() : Shape3d {

        val hinge = HingeLayingFlat(outerD, innerD, length, pieces)

        val plate = Square( width-1, length)
            .roundCorner(2,radius)
            .roundCorner(1,radius)
            .extrude( thickness ).centerY()
            .leftTo(1)

        val hole = countersink( screwD, screwHeadD )
            .translateX(outerD/4 + width/2) // Center the holes
            .topTo(plate.top+0.01)
         val holes = hole.repeatY(holeCount, length/holeCount ).centerY()
            
        val plates = (plate - holes).mirrorX().also()

        return (hinge and plates)
    }
}