import uk.co.nickthecoder.foocad.smartextrusion.v1.* import static uk.co.nickthecoder.foocad.smartextrusion.v1.SmartExtrusion.* import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.* import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.* import uk.co.nickthecoder.foocad.extras.v1.* import static uk.co.nickthecoder.foocad.extras.v1.Extras.* class Einstein : Model { @Custom val length = 20 @Custom var thickness = 2 @Custom var chamfer = 0.5 @Custom var round = 0.5 @Custom var clearance = 0.3 meth hatShape() : Shape2d { val short = length / (2*Math.cos( Math.PI/6 )) var direction = Vector2(1,0) val a = 60 return PolygonBuilder().apply { moveTo(0,0) lineBy( direction * length ) direction = direction.rotateDegrees(-60) lineBy( direction * length ) direction = direction.rotateDegrees(-90) lineBy( direction * short ) direction = direction.rotateDegrees(-a) lineBy( direction * short ) direction = direction.rotateDegrees(90) lineBy( direction * length ) direction = direction.rotateDegrees(-a) lineBy( direction * length ) direction = direction.rotateDegrees(-90) lineBy( direction * short ) direction = direction.rotateDegrees(a) lineBy( direction * short ) direction = direction.rotateDegrees(-90) lineBy( direction * length ) direction = direction.rotateDegrees(a) lineBy( direction * length ) direction = direction.rotateDegrees(-90) lineBy( direction * short ) direction = direction.rotateDegrees(-a) lineBy( direction * short*2 ) }.build() } meth kiteLines( thickness : double ) : Shape2d { val short = length / (2*Math.cos( Math.PI/6 )) var direction = Vector2(1,0).rotateDegrees(-120) val path1 = PolygonBuilder().apply { moveTo( length, 0 ) lineBy( direction * length ) direction = direction.rotateDegrees(-90) lineBy( direction * short ) direction = direction.rotateDegrees(-60) lineBy( direction * short ) direction = direction.rotateDegrees(90) lineBy( direction * length ) direction = direction.rotateDegrees(-120) lineBy( direction * length ) }.buildPath() val path2 = PolygonBuilder().apply { moveTo( -length, 0 ) direction = Vector2(1,0).rotateDegrees(-60) lineBy( direction * length ) direction = direction.rotateDegrees(-90) lineBy( direction * short ) }.buildPath() val path3 = PolygonBuilder().apply { moveTo( 0, short ) direction = Vector2(1,0).rotateDegrees(-150) lineBy( direction * short ) direction = direction.rotateDegrees(90) lineBy( direction * length ) }.buildPath() return path1.thickness(thickness) + path2.thickness(thickness) + path3.thickness(thickness) } meth hat() : Shape3d { val plainShape = hatShape().offset(-clearance) val shape = plainShape.intersection( plainShape.roundAllCorners(round) ) val main = shape.smartExtrude( thickness ) .edges( Chamfer( chamfer ) ) val lines = kiteLines( 0.5 ) .smartExtrude( chamfer ) .top( Chamfer( chamfer -0.01).reverse() ) .topTo(main.top + 0.01) return main - lines } override fun build() : Shape3d { return hat() } }