分享
 
 
 

用Pline绘制齿轮

王朝other·作者佚名  2008-05-21
窄屏简体版  字體: |||超大  

〖说明〗本例程能够根据给定的直径、齿数和角度绘制齿轮轮廓线。绘成 的轮廓是连续的polyline,能方便地进行三维延伸等处理。不过其中曲线生成采用的数据是根据美国机械行业标准,用的时候可能要根据自己的需要修改。

〖安装〗将"程序代码"一节的文本裁剪下来,保存成名为"SUPRGEAR.LSP"的 文本文件;将这个文件拷贝到AutoCAD的系统目录中。

〖使用〗在AutoCAD命令行键入:(load "suprgear")

然后执行:SG,按程序中的提示操作即可。

〖程序代码〗;;;begain suprgear.lsp;*************************************************;SPURGEAR.LSP - a lisp program by Tony Hotchkiss;――; This routine draws a spur gear using joined; polylines. It lets you use any pressure angle; to design the gear teeth.;*************************************************(defun err (s)

(if (= s "Function cancelled")

(princ "\nSPURGEAR - cancelled: ")

(progn (princ "\nSPURGEAR - Error: ") (princ s)

(terpri))); if(resetting)

(princ "SYSTEM VARIABLES have been reset\n")

(princ)); err

(defun setv (systvar newval)

(setq x (read (strcat systvar "1")))

(set x (getvar systvar))

(setvar systvar newval)); setv

(defun setting ()

(setq oerr *error*)

(setq *error* err)

(setv "CMDECHO" 0)

(setv "BLIPMODE" 0)); end of setting(defun rsetv (systvar)

(setq x (read (strcat systvar "1")))

(setvar systvar (eval x))); restv(defun resetting ()

(rsetv "CMDECHO")

(rsetv "BLIPMODE")

(setq *error* oerr)); end of resetting

(defun dxf (code ename)

(cdr (assoc code (entget ename)))); dxf

(defun spurgear (/ D N phi DO RO A B DR DB inv-plst p1 trimcode invent p0 p curvent linent linent2 ent2 p2)

(setq D (getreal "\nPitch diameter: ")

N (getint "\nNumber of teeth: ")

phi (getreal "\nPressure angle: ")

phi (* (/ phi 180) pi) ; Pressure angle DO (* D (+ (/ 2.0 N) 1.0)); Outside diameter RO (/ DO 2.0) ; Outside radius A (/ D N) ; Addendum B (* 1.25 A) ; Dedendum DR (- D (* B 2.0)) ; Root diameter DB (* D (cos phi)) ; Base circle dia. inv-plst (involute DB N phi);involute points trimcode nil); setq(command "ZOOM" (list 0 (- B))

(list RO (/ RO 1.5))); command(setq invent (draw-inv inv-plst)); Draw involute.(setq p0 (car inv-plst)

trimcode (ext-trim p0 DR D);trim or extend); setq ; the involute.(if (and trimcode (= trimcode 0))

(progn ; Joins the involute to the extension.(setq p (list (/ DR 2.0) 0))

(command "PEDIT" p "Y" "J" invent "" "X")

(setq curvent (entlast))); progn(setq curvent (entlast))); if(if (null trimcode) (setq curvent invent))

(setq linent (draw-top-line D DB N RO)); top line.(command "COPY" linent "" "0,0" "0,0")

(setq linent2 (entlast))

(setq ent2 (mir-it curvent linent)); mirror curve(command "PEDIT" curvent "J" linent ent2 "" "X")

(segment DR N linent2) ; Finish the job!

(setq p1 (list (- RO) (- RO)))

(setq p2 (list RO RO))

(command "ZOOM" p1 p2)

(prompt "\nConverting to POLYLINE, please wait……")

(command "PEDIT" (entlast) "J" "C" p1 p2 "" "X")

(prompt "\nAll done!")); spurgear

(defun involute (DB N phi / numer denom frac theta2max thetamax theta-inc theta plist RB xval yval p)

(setq invfact 3)

(setq numer (+ N 2.0)

denom (* N (cos phi))

frac (/ numer denom)

theta2max (- (* frac frac) 1)

thetamax (sqrt theta2max)

theta-inc (/ thetamax (float invfact))

theta 0 plist nil RB (/ DB 2.0)); setq(repeat (1+ invfact)

(setq xval (do-x RB theta)

yval (do-y RB theta)

p (list xval yval)

plist (append plist (list p))); setq(setq theta (+ theta theta-inc))); repeat plist); involute

(defun do-x (RB theta)

(* RB (+ (cos theta) (* theta (sin theta))))); do-x

(defun do-y (RB theta)

(* RB (- (sin theta) (* theta (cos theta))))); do-y

(defun draw-inv (inv-plst / dirpt plist p)

(command "PLINE" (nth 0 inv-plst))

(setq dirpt (polar (nth 0 inv-plst) 0 1))

(command "A" "D" dirpt)

(setq plist (cdr inv-plst))

(foreach p plist (command p))

(command "")

(entlast)); draw-inv

(defun ext-trim (p0 DR D / trimcode dist endr)

(if (> (car p0) (/ DR 2.0)) ; Extends the involute(progn(command "LINE" (list (/ DR 2.0) 0) p0 "")

(setq trimcode 0)); progn); if(if (< (car p0) (/ DR 2.0)) ; Trims the involute(progn(command "CIRCLE" "0,0" "D" DR); Root circle(setq dist (- (/ D 2.0) (car p0)))

(command "ZOOM" p0(polar p0 0.6 dist))

(setq endr (entlast))

(command "TRIM" endr "" p0 "")

(command "ZOOM" "P")

(entdel endr)

(setq trimcode 1)); progn); if trimcode); ext-trim

(defun draw-top-line (D DB N RO / theta-p xp yp alpha beta tang angend inv-endpt lend)

(setq theta-p (sqrt (- (* (/ D DB) (/ D DB)) 1.0))

xp (do-x (/ DB 2.0) theta-p); This section yp (do-y (/ DB 2.0) theta-p); sets up angles alpha (atan yp xp) ; for drawing a abeta (angle (list 0 0) (last inv-plst))

beta (- abeta alpha) ; line across the tang (/ pi N) ; top of a tooth angend (- (+ alpha tang) beta)

inv-endpt (last inv-plst); This also creates lend (polar (list 0 0) angend RO); the tooth); setq ; thickness.(command "LINE" inv-endpt lend ""); Draws the line(redraw)

(entlast)); draw-top-line

(defun mir-it (cvent linent / pt)

(setq pt (dxf 11 linent))

(command "MIRROR" cvent "" "MID" pt "0,0" "")

(entlast)); mir-it

(defun segment (DR N en / p1 p2 ang dist midp p0 pang pang2 p p3 ent3 entl1 entl2 en1 en2)

(setq p1 (dxf 10 en)

p2 (dxf 11 en)

ang (angle p1 p2)

dist (/ (distance p1 p2) 2.0)

midp (polar p1 ang dist)

p0 (list 0 0)

pang (angle p0 midp)

pang2 (/ pi N)

p (polar p0 pang (/ DR 2.0))

p1 (polar p0 (- pang pang2) (/ DR 2.0))

p2 (polar p0 (+ pang pang2) (/ DR 2.0))

p3 (polar p0 (+ pang pang2 pang2) (/ DR 2.0))

ent3 (entlast); This is the tooth p-line); setq(command "ZOOM" "W" p3 p1)

(command "CIRCLE" "0,0" "D" DR) ;Root circle(command "TRIM" ent3 "" p ""); Trim the root circle(command "ZOOM" "P")

(command "LINE" p0 p1 "")

(setq entl1 (entlast))

(command "LINE" p0 p2 "")

(setq entl2 (entlast))

(command "TRIM" entl1 entl2 "" p3 "")

(entdel entl1)

(entdel entl2)

(entdel en)

(command "ZOOM" "W" p3 p1)

(command "PEDIT" p1 "Y" "X")

(setq en1 (entlast))

(command "PEDIT" p2 "Y" "X")

(setq en2 (entlast))

(command "PEDIT" en1 "J" midp en2 "" "X")

(command "ZOOM" "P")

(command "ARRAY" p1 "" "P" "0,0" N "360" "Y")); segment

(defun c:sg ()

(setting)

(spurgear)

(resetting)

(princ)); c:sg

(prompt "\n**SPURGEAR.LSP Loaded!")

(prompt "\n Enter 'SG' to start")

;;;end suprgear.lsp

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有