Exit Full View
Up

/Garden/RotatingJoint.foocad

RotatingJoint
FooCAD Source Code
class RotatingJoint : Model {
    
    var inner = 6
    var outer = 8
    var height = 6 

    val slack = 0.3
    val vSlack = 0.2
    var sides = 20

    // I have problems calibrating my printer - often the bed is too high,
    // and the first layer is smudged outwards. A chamfer will help
    // prevent the two parts from fusing.
    var chamfer = 0.4


    fun axel() : Shape3d {
        val largeP = Circle(inner/2).sides(sides)
        val smallP = Circle(inner/2-height/4).sides(sides)
        val fullP = Circle(outer/2).sides(sides)

        val result = ExtrusionBuilder().apply {
            if (chamfer != 0) {
                crossSection( largeP.offset( -chamfer ) )
                forward(chamfer)
            }
            crossSection( largeP )
            forward( height/2 -chamfer )
            crossSection( smallP )
            forward( height/2 )
            crossSection( fullP )
            crossSection()
        }.build()

        return result
    }

    fun void() : Shape3d {
        val largeP = Circle.hole( inner/2 + slack ).sides(sides)
        val smallP = Circle( inner/2-height/4 + slack).sides(sides)
        val fullP = Circle(outer/2 + slack).sides(sides)

        val result = ExtrusionBuilder().apply {
            forward( -0.001 )
            crossSection( largeP )
            forward( height/2 )
            crossSection( smallP )
            forward( height/2 + 0.002 )
            crossSection( fullP )
        }.build()

        return result
    }

    fun bottom() : Shape3d {
        val solid = Cylinder( height/2, outer/2 ).sides(sides) +
            Cube( 10, inner/2, height ).centerY().translateX(-10)
        return solid - void()
    }

    fun top() : Shape3d {
        
        val axel : Shape3d = axel()
        val top = Cube( 10, inner/2, height/2-vSlack).centerY()
            .translateZ(height/2+vSlack)
        val bottom = Cube( 10, inner/2, height).centerY() -
            Cylinder( height + 0.002, outer/2 + slack ).sides(sides).translateZ(-0.001) -
            Cylinder( chamfer + 0.002, outer/2 + slack + chamfer , outer/2 + slack ).sides(sides).translateZ(-0.001)
        return axel + top + bottom
            
            
    }

    fun join( a : Shape3d, b : Shape3d, atX : double, atY : double ) : Shape3d {
        val axel : Shape3d = axel()
        val remove = Cylinder( height/2 + vSlack + 0.002, outer/2 + slack ).sides(sides).translateZ(-0.001) +
            Cylinder( chamfer + 0.002, outer/2 + slack + chamfer , outer/2 + slack ).sides(sides).translateZ(-0.001)
        val bottomRing = Cylinder( height/2, outer/2 ).sides(sides)

        return (a + bottomRing.translate(atX, atY,0) - void().translate(atX, atY,0)) +
            axel.translate(atX, atY,0) +
            (b - remove.translate(atX, atY,0))
    }

    override fun build() : Shape3d {

        return join(
            Cube( 10, inner/2, height ).centerY().translateX(-10).color("Blue"),
            Cube( 10, inner/2, height ).centerY().color("Green").brighter(),
            0,0
        ) +
        join(
            Cube( 10, inner/2, height ).centerY().translateX(-110).color("Blue"),
            Cube( 10, inner/2, height ).centerY().translateX(-100).color("Green").brighter(),
            -100,0
        )
    }
}