import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.* import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.* class KryptoniteBikeLockMount : Model { var sectionDiameter = 42 var thickness = 3.0 var lockSize = Vector2( 52 , 26 ) var height = 60 var angle = 30 var headD = 46 fun clip() : Shape3d { var profile = Circle( sectionDiameter/2 ) val fastnerP = Square(10 + thickness,10).centerY().rightTo(0).roundCorner(3,2).roundCorner(0,2) val fastner = ExtrusionBuilder().apply { crossSection( fastnerP.scaleX(0.1) ) forward(4) crossSection(fastnerP) forward(10) crossSection() }.build().rightTo(-sectionDiameter/2) val holes = ( Cylinder( 10, 2 ).rotateX(90) + Cylinder( 10, 2.3 ).rotateX(-90) ).translateX( fastner.middle.x - thickness/2 ) .mirrorX().also().translateZ(4 + 5) val fastners = (fastner - holes).mirrorX().also() .spreadZ( 2, height, 0.1 ) val ring = profile.offset( thickness ) val clip = ring.extrude( height ) val gap = Cube( fastners.size.x + 2, 1, height + 2 ).bottomTo(-1).centerXY() val center = Cylinder( 100, sectionDiameter/2 ).bottomTo(-1) return (clip + fastners - gap) remove center } fun lock() : Shape3d { return Cube( lockSize.x, lockSize.y, 160 ).centerXY() + Cylinder( lockSize.x + 10, headD/2 ).center().rotateY(90).translateZ(160) } fun cage() : Shape3d { val foo = 10 val profile = (Square( lockSize.x + thickness*2 , lockSize.y + thickness*2 ) .center().roundAllCorners( thickness + 1 ) hull Square( 20, 1 ).center().frontTo( headD/2 + sectionDiameter/2 + thickness ) ) - Square( lockSize ).roundAllCorners(1) .center() val main = profile.extrude( height ) val curve = Cylinder( main.size.x + 2, headD/2 ).center() .rotateY(90) .bottomTo(main.top-10)//.previewOnly() val slope = Cube( main.size.x *2, 100, 100 ) .centerX().backTo(0).rotateX(angle).translateZ(curve.bottom)//.previewOnly() return main - slope - curve + lock().topTo(height + headD ).previewOnly() } @Piece fun partA() : Shape3d = build() / Cube( 1000 ).centerX().backTo(0) @Piece fun partB() : Shape3d = build() / Cube( 1000 ).centerX().frontTo(0) override fun build() : Shape3d { val clip : Shape3d = clip() val cage : Shape3d = cage().backTo(0) return clip and cage } }