import uk.co.nickthecoder.foocad.smartextrusion.v1.* import static uk.co.nickthecoder.foocad.smartextrusion.v1.SmartExtrusion.* import uk.co.nickthecoder.foocad.screws.v3.* import uk.co.nickthecoder.foocad.threaded.v2.* class CurvedAttachment : Model { @Custom var thread = Thread( 12, 2 ) @Custom var depth = 10 @Custom var curveDiameter = 100 @Custom var washerThickness = 1.0 @Custom var lipWidth = 4 @Piece meth washerCurvedExterior() : Shape3d { val inner = Circle( thread.diameter/2 ) val outer = Circle( thread.diameter/2 + lipWidth ) val solid = (outer - inner).extrude( 30 ) val curve = Circle( curveDiameter/2 ).extrude( outer.size.x + 1 ) .rotateY(90) .bottomTo( washerThickness ) .centerXY() return solid - curve } @Piece meth washerCurvedInterior() : Shape3d { val largeRadius = thread.diameter/2 + lipWidth val inner = Circle( thread.diameter/2 ) val outer = Circle( largeRadius ) val angle = Math.asin( largeRadius / (curveDiameter/2) ) val cy = Math.cos( angle ) * curveDiameter/2 val solid = (outer - inner).extrude( 30 ) val curve = Circle( curveDiameter/2 ).extrude( outer.size.x + 1 ) .rotateY(90) .translateZ(-cy + washerThickness) .centerXY() return solid.intersection( curve ) } @Piece meth threadedRod( length : double ) : Shape3d { return thread.threadedRod( length ) .chamferBottom(false) } @Piece meth bolt() : Shape3d { return thread.bolt( depth ) } @Piece meth nut() : Shape3d { return thread.nut() } @Custom var squareAttachmentSize = Vector3( 20, 30, 10 ) @Piece meth squareAttachment() : Shape3d { val baseThickness = 1.2 val wallThickness = 3 val cutoutShape = Square( squareAttachmentSize.x, squareAttachmentSize.y ) .center().roundAllCorners(1,4) val headShape = cutoutShape.offset( wallThickness ) val newHead = headShape .smartExtrude(squareAttachmentSize.z + baseThickness ) .top( Chamfer(1) ) val cutout = cutoutShape .smartExtrude( newHead.size.z - 3 ) .bottom( Chamfer(0.4).reverse() ) .bottomTo(-0.01) val rod = threadedRod( depth + baseThickness ).bottomTo( newHead.top - baseThickness ) val screwHole = Countersink.medium().topTo( rod.top ) return newHead + rod - cutout - screwHole } @Piece meth slottedAttachment() : Shape3d { val baseThickness = 1.2 val wallThickness = 3 val cutoutShape = Square( squareAttachmentSize.x, squareAttachmentSize.y ) .center().roundAllCorners(1,4) val headShape = Square( squareAttachmentSize.x + wallThickness *2, squareAttachmentSize.y + wallThickness ) .center().roundAllCorners(1+wallThickness,4).translateY(-wallThickness/2-0.1) val newHead = headShape .smartExtrude(squareAttachmentSize.z + baseThickness ) .top( Chamfer(1) ) val cutout = cutoutShape .smartExtrude( newHead.size.z - 3 ) .bottom( Chamfer(0.4).reverse() ) .bottomTo(-0.01) val rod = threadedRod( depth + baseThickness ).bottomTo( newHead.top - baseThickness ) val screwHole = Countersink.medium().topTo( rod.top ) return rod + newHead - cutout - screwHole } override fun build() : Shape3d { val container = Circle( curveDiameter/2 ).extrude( curveDiameter/2 ) .previewOnly() val washerIn = washerCurvedInterior() .rotateY(90) .translateZ( curveDiameter/4 ) .rightTo( curveDiameter/2 - 1 ) .color("Green") val washerOut = washerCurvedExterior() .rotateY(-90) .translate( curveDiameter/2 + washerThickness, 0, curveDiameter/4 ) .color("Green") val bolt = bolt() .rotateY(90) .translateZ( curveDiameter/4 ) .leftTo( washerIn.left - thread.headSize.y ) val nut = nut() .rotateY(90) .translateZ( curveDiameter/4 ) .leftTo( bolt.right + 1 ) return container + washerOut + washerIn + bolt + nut } }