效果图:
这个代码风格照搬了我写WINDOWS驱动代码时的风格。- //code by Tesla.Angela (www.m5home.com/bbs)
- $fn=100;
- module ObCreateHollowCylinder(radius,height,thickness,IsCone)
- {
- difference()
- {
- cylinder(height,radius,IsCone?0:radius);
- cylinder(height-thickness,radius-thickness,IsCone?0:radius-thickness);
- }
- }
- //demo
- translate([80,0,100])
- {
- rotate([0,180,0])
- {
- ObCreateHollowCylinder(50,100,2,0);
- }
- }
- translate([-30,0,0])
- {
- ObCreateHollowCylinder(50,100,2,1);
- }
- module ObCreateHollowHalfBall(radius,thickness)
- {
- difference()
- {
- sphere(radius);
- sphere(radius-thickness);
- translate([0,-radius,-radius])
- {
- cube([radius*2,radius*2,radius*2]);
- }
- }
- }
- //demo
- translate([-30,110,50])
- {
- rotate([0,270,0])
- {
- ObCreateHollowHalfBall(50,2);
- }
- }
- module ObpCreatePyramid(length, height)
- {
- polyhedron
- (
- points=[[0,length,0],[length,length,0],[length,0,0],[0,0,0],[length/2,length/2,height]],
- faces=[[0,1,4],[1,2,4],[2,3,4],[3,0,4],[3,2,1,0]]
- );
- }
- module ObCreateHollowPyramid(length, height,thickness)
- {
- difference()
- {
- ObpCreatePyramid(length, height);
- translate([thickness/2,thickness/2,0])
- {
- ObpCreatePyramid(length-thickness, height-thickness);
- }
- }
- }
- //demo
- translate([30,60,0])
- {
- ObCreateHollowPyramid(100,100,10);
- }
复制代码 |