nowindxdw
11/2/2017 - 2:36 AM

openScad study2

example006最终效果是一个骰子

module example006()
{
//定义一个函数edgeprofile,边角效果
module edgeprofile()
{
//渲染(凸性为2,此处不明白convexity,更改此值-2~+1000未见显著影响)
render(convexity = 2) difference() {
//长方柱体基础
cube([20, 20, 150], center = true);
//减掉一段圆柱
translate([-10, -10, 0])
cylinder(h = 80, r = 10, center = true);
//减掉上下两个小球
translate([-10, -10, +40])
sphere(r = 10);
translate([-10, -10, -40])
sphere(r = 10);
}
}

//立方体减去边角,得到非常圆润的立方体
difference()
{
cube(100, center = true);
//对下面图形复制3份进行旋转
for (rot = [ [0, 0, 0], [1, 0, 0], [0, 1, 0] ]) {
rotate(90, rot)
//p是一个4个元素的坐标数组,每个元素,第一个是X偏移值,第二个是Y偏移值,第三个是旋转角度
for (p = [[+1, +1, 0], [-1, +1, 90], [-1, -1, 180], [+1, -1, 270]]) {
translate([ p[0]*50, p[1]*50, 0 ])
rotate(p[2], [0, 0, 1])
edgeprofile();
}
}
//下面构造6个面的点数,6个面,不同数目的圆球
for (i = [
//1点
[ 0, 0, [ [0, 0] ] ],
//2点
[ 90, 0, [ [-20, -20], [+20, +20] ] ],
//6点
[ 180, 0, [ [-20, -25], [-20, 0], [-20, +25], [+20, -25], [+20, 0], [+20, +25] ] ],
//5点
[ 270, 0, [ [0, 0], [-25, -25], [+25, -25], [-25, +25], [+25, +25] ] ],
//3点
[ 0, 90, [ [-25, -25], [0, 0], [+25, +25] ] ],
//4点
[ 0, -90, [ [-25, -25], [+25, -25], [-25, +25], [+25, +25] ] ]
]) {
rotate(i[0], [0, 0, 1]) rotate(i[1], [1, 0, 0]) translate([0, -50, 0])
for (j = i[2])
translate([j[0], 0, j[1]]) sphere(10);
}
}
}

example006();


7
//首次引入dxf文件,研究后发现就是方便工程制图的软件,对于精度要求非常高,造型比较复杂的很适用,不过要学工程制图的一些东西也相当大的一个工程量
module cutout()
{
intersection()
{
rotate(90, [1, 0, 0])
translate([0, 0, -50])
linear_extrude(height = 100, convexity = 1)
import(file = "example007.dxf", layer = "cutout1");
rotate(90, [0, 0, 1])
rotate(90, [1, 0, 0])
translate([0, 0, -50])
linear_extrude(height = 100, convexity = 2)
import(file = "example007.dxf", layer = "cutout2");
}
}

module clip()
{
difference() {
// NB! We have to use the deprecated module here since the "dorn"
// layer contains an open polyline, which is not yet supported
// by the import() module.
rotate_extrude(
file = "example007.dxf",
layer="dorn",
convexity = 3);
for (r = [0, 90])
rotate(r, [0, 0, 1])
cutout();
}
}

module cutview()
{
difference()
{
difference()
{
translate([0, 0, -10])
clip();

rotate(20, [0, 0, 1])
rotate(-20, [0, 1, 0])
translate([18, 0, 0])
cube(30, center = true);
}

# render(convexity = 5) intersection()
{
translate([0, 0, -10])
clip();
rotate(20, [0, 0, 1])
rotate(-20, [0, 1, 0])
translate([18, 0, 0])
cube(30, center = true);
}
}
}

translate([0, 0, -10])
clip();

// cutview();





此处首次出现import dxf文件,查看dxf文件需另装CAXA电子图版http://mydown.yesky.com/soft/multimedia/manipulate/24/459524_more.shtml
8

difference()
{
intersection()
{
translate([ -25, -25, -25])
linear_extrude(height = 50, convexity = 3)
import(file = "example008.dxf", layer = "G");
rotate(90, [1, 0, 0])
translate([ -25, -125, -25])
linear_extrude(height = 50, convexity = 3)
import(file = "example008.dxf", layer = "E");
rotate(90, [0, 1, 0])
translate([ -125, -125, -25])
linear_extrude(height = 50, convexity = 3)
import(file = "example008.dxf", layer = "B");
}

intersection()
{
translate([ -125, -25, -26])
linear_extrude(height = 52, convexity = 1)
import(file = "example008.dxf", layer = "X");

rotate(90, [0, 1, 0])
translate([ -125, -25, -26])
linear_extrude(height = 52, convexity = 1)
import(file = "example008.dxf", layer = "X");
}
}

9得到一个螺旋桨工程图,涉及调用尺寸和图层,比较复杂,占不深入研究

bodywidth = dxf_dim(file = "example009.dxf", name = "bodywidth");
fanwidth = dxf_dim(file = "example009.dxf", name = "fanwidth");
platewidth = dxf_dim(file = "example009.dxf", name = "platewidth");
fan_side_center = dxf_cross(file = "example009.dxf", layer = "fan_side_center");
fanrot = dxf_dim(file = "example009.dxf", name = "fanrot");

% linear_extrude(height = bodywidth, center = true, convexity = 10)
import(file = "example009.dxf", layer = "body");

% for (z = [+(bodywidth/2 + platewidth/2),
-(bodywidth/2 + platewidth/2)])
{
translate([0, 0, z])
linear_extrude(height = platewidth, center = true, convexity = 10)
import(file = "example009.dxf", layer = "plate");
}

intersection()
{
linear_extrude(height = fanwidth, center = true, convexity = 10, twist = -fanrot)
import(file = "example009.dxf", layer = "fan_top");
// NB! We have to use the deprecated module here since the "fan_side"
// layer contains an open polyline, which is not yet supported
// by the import() module.
rotate_extrude(file = "example009.dxf", layer = "fan_side",
origin = fan_side_center, convexity = 10);
}

10

// example010.dat generated using octave:?
//此处首次出现.DAT文件,其实就是数据格式文件,可用EXCEL查看,是一组横纵坐标数据,可根据下面公式生成,用于绘制各种曲面
// d = (sin(1:0.2:10)' * cos(1:0.2:10)) * 10;
// save("example010.dat", "d");
//此处用到intersection表示计算两个图形交叉后得到的图形
intersection()
{
surface(file = "example010.dat",
center = true, convexity = 5);
rotate(45, [0, 0, 1])
surface(file = "example010.dat",
center = true, convexity = 5);