Exit Full View
ZipUp

/Bike/BackLightExtension.foocad

BackLightExtension

With a box on the back of my bike, the back light is too far forward. This goes between the existing fittings.

The "alt" version also moves the light down (as well as back).

FooCAD Source Code
import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.*
import static uk.co.nickthecoder.foocad.chamferedextrude.v1.ChamferedExtrude.*

class BackLightExtension : AbstractModel() {

    @Custom( about="The distance between the screw holes" )
    var holeDistance = 60

    @Custom( about="The length of the extension" )
    var extension = 90 // Was 80

    @Custom
    var height = 14

    @Piece
    meth newVersion() : Shape3d {
        val thickness = 12
        val largeR = 70
        val down = 70
        val path = PolygonBuilder().apply {
            moveTo(0,thickness/2)
            lineBy( 0, -down + largeR - thickness)
            circularArcBy( Vector2( largeR, -largeR ), largeR, false, true )
            lineBy( extension - largeR - thickness/2, 0 )
        }.buildPath()

        val profile = Square(thickness, holeDistance + thickness*2 ).center()
            .roundAllCorners(1,1)

        val main = profile.extrude(path)

        val holes = Cylinder( thickness, 5.5/2 )
            .rotateY(90)
            .translate( -12/2, -12/2, 0 )
            .translateZ(-holeDistance/2).translateZ(holeDistance).also()
            .translate( extension-thickness, -down, 0).also()

        val foo = Cube( 1, 50, 1 ).previewOnly().backTo(0)
        return (main - holes).bottomTo(0) + foo
    }

    @Piece
    meth testNewShape() = newVersion().intersection( Cube( 300 ).centerXY().topTo(1) )

    @Piece
    meth oldVersion() : Shape3d {
        val solid = Square( holeDistance + 20, extension )
            .center()
            .roundAllCorners(4)
            .chamferedExtrude( height, 1 )

        val diameter = 5.5
        val hole = Circle( diameter/2 )
            .chamferedExtrude( extension, -1, -1 )
            .center()
            .rotateX(90)
            .translate( holeDistance/2, 0, height/2 )

        val holes = hole.mirrorX().also()

        /*
        val extraLayers = Cube( 0.3, extension, 0.3 )
            .spreadX( 4, diameter )
            .centerY()
            .centerXTo( holeDistance/2 )
            .bottomTo( height/4 - diameter/4 )
            .topTo( height - height/4 + diameter/4 ).also()
            .mirrorX().also()
            .color("Red")
        */
        return solid /*- extraLayers*/ - holes
    }

    override meth build() : Shape3d {
        return newVersion()
    }
}