本文主要是介绍在Python里应用Openscad实现3D建模之3D螺纹建模初探3,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在Python里应用Openscad实现3D建模(修改简化版)-4
–SolidPython学习笔记3
- –form https://github.com/SolidCode/SolidPython
参考Parkinbotshortcuts.scad做了部分修改使得代码更为简洁易读
以下是对solidpython的readme的学习笔记(其中的部分code进行了简化):
3D螺纹建模初探3
絮絮叨叨
- 到目前我们已经分析了3D螺纹建模的2个解决方案:扭出来和糊出来(好恶俗的名字。。。)
- 从以上的分析中我们应用PY代码初步实现了标准化的(符合ISO261)3D螺纹
- 接下来我们探讨目前最为流行的方案,并进一步实现定制
方案三:垒出来 Solution Three: Sweep polyhedrons
- 该方案是目前thingiverse上最为流行的方案包括:
- NUT JOB | Nut, Bolt, Washer and Threaded Rod Factory by mike_mattala - Thingiverse
- Poor man’s openscad screw library by aubenc - Thingiverse
- Screw Library by syvwlch - Thingiverse
- screw_thread.py
- 该方案首先创建一个多面体,然后螺旋堆叠出来一个巨大的多面体
- 这个方案不太好懂,以上几种方案中第一和第二个方案(较早)的螺纹建模(姑且叫衰人(Poorman)方案吧)是一样的,而Poorman的作者aubenc提到了更早的第3个方案
- 以下就是
衰人方案:
scad代码:
module full_thread (ttn,//ttn=round(length/P)+1;圈数st, //Psn, //sn=floor(Dmaj*pi/fs);fs=pi/2 sengments 圆段数zt, // zt=P/fnIfxy, //angle_xy=360/fn;or, // Rmajir //Rmin)
{if(ir >= 0.2){for(i=[0:ttn-1]){for(j=[0:sn-1]){pt = [[0,0,i*st-st],[ir*cos(j*angle_xy), ir*sin(j*angle_xy), i*st+j*zt-st ],[ir*cos((j+1)*angle_xy), ir*sin((j+1)*angle_xy), i*st+(j+1)*zt-st ],[0,0,i*st],[or*cos(j*angle_xy), or*sin(j*angle_xy), i*st+j*zt-st/2 ],[or*cos((j+1)*angle_xy), or*sin((j+1)*angle_xy), i*st+(j+1)*zt-st/2 ],[ir*cos(j*angle_xy), ir*sin(j*angle_xy), i*st+j*zt ],[ir*cos((j+1)*angle_xy), ir*sin((j+1)*angle_xy), i*st+(j+1)*zt ],[0,0,i*st+st]];polyhedron(points=pt,faces=[[1,0,3],[1,3,6],[6,3,8],[1,6,4], //changed triangles to faces (to be deprecated)[0,1,2],[1,4,2],[2,4,5],[5,4,6],[5,6,7],[7,6,8],[7,8,3],[0,2,3],[3,2,7],[7,2,5] ]);}}}else{echo("Step Degrees too agresive, the thread will not be made!!");echo("Try to increase de value for the degrees and/or...");echo(" decrease the pitch value and/or...");echo(" increase the outer diameter value.");}
}
- 我们看一下生成的螺纹的截面:
- 可以看出仍是个伪标准螺纹,我们在下面的scad代码中修改一下
- Or = Rmaj + 1 / 8 * H
- 应用布尔运算修改
衰人方案ISO标准修订版之scad代码
use <shortcuts.scad>;
use<Nut_Job.scad>;
Dmaj = 10;
P = 1;
H = .866 * P;
$fn = 36;
length = 10;
Rmaj = Dmaj / 2;
Rmin = Dmaj / 2 - 5 / 8 * H;
Od = Dmaj+H/4
projection(){Ry(90)I(){U(){Tz(.5*length)Cy(r=Rmin, h=length);screw_thread(Od,1,30,10,PI*5/18,0);};Tz(.5*length)Cy(r=Rmaj, h=length);}
}
- 当然了还有一种方法就是直接修改多面体参数(比如:Po,Fa)
衰人方案ISO标准修订版之python代码:
from solid import *
from solid.utils import *
import viewscadr = viewscad.Renderer(openscad_exec=r'/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD')
Dmaj = 10
P = 1
H = .866 * P
segments = 60
length = 10
Rmaj = Dmaj / 2
Rmin = Dmaj / 2 - 5 / 8 * H
def thread_p(Dmaj=10,P=1,length=10):angle_xy = 2 * pi / segmentszt = P / segmentsttn = round(length / P)p3 = 0c = []for i in range(0,ttn):for j in range(0,segments):Po = [ [ 0, 0, i*P+ P ],#中轴上#近截面[Rmin*cos( j *angle_xy), Rmin*sin( j *angle_xy), i*P+ 1/2 *P + j *zt],[Rmin*cos( j *angle_xy), Rmin*sin( j *angle_xy), i*P+ 3/8 *P + j *zt],[Rmaj*cos( j *angle_xy), Rmaj*sin( j *angle_xy), i*P+ 1/16 *P + j *zt],[Rmaj*cos( j *angle_xy), Rmaj*sin( j *angle_xy), i*P- 1/16 *P + j *zt],[Rmin*cos( j *angle_xy), Rmin*sin( j *angle_xy), i*P- 3/8 *P + j *zt],[Rmin*cos( j *angle_xy), Rmin*sin( j *angle_xy), i*P- 1/2 *P + j *zt],#远截面[Rmin*cos((j+1)*angle_xy), Rmin*sin((j+1)*angle_xy), i*P+ 1/2 *P +(j+1)*zt],[Rmin*cos((j+1)*angle_xy), Rmin*sin((j+1)*angle_xy), i*P+ 3/8 *P +(j+1)*zt],[Rmaj*cos((j+1)*angle_xy), Rmaj*sin((j+1)*angle_xy), i*P+ 1/16 *P +(j+1)*zt],[Rmaj*cos((j+1)*angle_xy), Rmaj*sin((j+1)*angle_xy), i*P- 1/16 *P +(j+1)*zt],[Rmin*cos((j+1)*angle_xy), Rmin*sin((j+1)*angle_xy), i*P- 3/8 *P +(j+1)*zt],[Rmin*cos((j+1)*angle_xy), Rmin*sin((j+1)*angle_xy), i*P- 1/2 *P +(j+1)*zt], [ 0, 0, i*P- P ]#中轴下]Fa =[ [0,1,2,3,4,5,6,13],[13,12,11,10,9,8,7,0],[7,1,0] ,[13,6,12],[2,1,7,8] ,[8,9,3,2],[4,3,9,10] ,[5,4,10,11],[6,5,11,12]]if j == 0 and i == 0:p3 = bac(P3(Po, Fa))#1st P3# p3 += C("red")(Rx()(Le(.1)(Pr()(Rx(90)(P3(Po, Fa))))))# sector of 1st P3# c = 0for x in range(0,len(Po)):p3 += translate(Po[x]) (C("red")(Sp(.05)))#Pop3 += translate(Po[x]) (Le(.01)(text(text= str(x),size=.2))) #num of Poc += P3(Po, Fa)# c += Rx()(C("red")(Le(.1)(Rx()(c))))#run the projection() too slow return p3, c
c = thread_p()[0]# scad_render_to_file(c, "thr_p.scad")
# r.render(c)
c
这是第一个修改后的多面体
c = thread_p()[1]
c
生成的螺纹
c = Pr()(Rx()(c))c
螺纹截面
这篇关于在Python里应用Openscad实现3D建模之3D螺纹建模初探3的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!