乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 36|回复: 9

[编程交流] 阿尔托Lisp程序

[复制链接]

1

主题

7

帖子

6

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 15:39:48 | 显示全部楼层 |阅读模式
20年前,我为理科硕士写了一个Lisp例程,但没法用,有人能帮忙吗,这是一个基于建筑师阿尔瓦·阿尔托作品的实验
 
  1. (defun dtr (a)
  2. (* pi (/ a 180.0))
  3. )
  4. (defun addz (pos inc / z)
  5. (setq z (caddr pos)
  6.           z (+ inc z)
  7.           pos (list (car pos) (cadr pos) z)
  8.           )
  9. )
  10. (defun rnge (bot top)
  11. (setq r (rand (- top bot))
  12.         r (+ bot r))
  13. )
  14. ;
  15. (defun rand (range / x z r)
  16. (if (not seed) (setq seed 350))
  17. (setq x (1 + (* seed 2197.0))
  18.            z (fix (/ x 4096.0))
  19.            seed (fix (- x (* z 4096.0)))
  20.            r (fix (1 + (abs (* (/ seed 4096.0) (- range 1.0)))))
  21. )
  22. )               
  23. (defun dvolp (pcn)
  24. (setq radb (distance ps pe)
  25.         angb (angle ps pcn)
  26.         psb (polar ps ang radb)
  27.         peb (polar pe (* ang anginc) radb)
  28.         )
  29. )
  30. ;
  31. (defun drawvolp (pcn)
  32. (setq radb (distance ps pe)
  33.         angb (angle ps pcn)
  34.         psb (polar ps ang radb)
  35.         peb (polar pe (+ ang anginc) radb)
  36.         radc (distance psb speb)
  37.         angc (angle psb speb)
  38.         angd (angle peb pe)
  39.         ange (angle ps pe)
  40.         angf (angle pe ps)
  41.         angg (angle peb pe)
  42.                 psc (polar psb angc (/ radc 2))
  43.                 psoa (polar psb angc (/ radc 2))
  44.                 psob (polar ps angc radc)
  45.                 psn (polar psob ange radc)
  46.                 peoa (polar pe angg (/ radc 2))
  47.                 peob (polar pe angg radc)
  48.                 pen (polar peob angf radc)
  49.                         htrad1 (distance psc peb)
  50.                         htrad2 (distance psoa peoa)
  51.                         htrad3 (distance psob peob)
  52.                                 psnht (addz psn htrad3)
  53.                                 psoaht (addz psoa htrad2)
  54.                                 pscht (addz psoa htrad1)
  55.                                 penht (addz pen htrad3)
  56.                                 peoaht (addz peoa htrad2)
  57.                                 pebht (addz peb htrad1)
  58.                                         )
  59.                         (command "layer" "m" "line" "c" 5 "" "")
  60.                         (command "3dface" psoa psoaht pscht psc "")
  61.                         (command "3dface" psc pscht pebht peb"")
  62.                         (command "3dface" peb pebht peoaht peoa "")
  63.                         (command "3dface" peoa peoaht penht pen "")
  64.                         (command "3dface" pen penht psnht psn "")
  65.                         (command "3dface" psn psnht psoaht psoa "")
  66.                         (command "3dface" pebht peoaht penht pebht "")
  67.                         (command "3dface" pscht psoaht psnht pscht "")
  68.                         (command "3dface" pebht penht psnht pscht "")
  69. )
  70. (defun dvolreg (pcn)
  71. (setq radt (fix (* (distance pte pts) (sqrt 2)))
  72.         anga (angle pts pcn)
  73.         angb (angle pte pcn)
  74.         ptsb (polar pts anga radt)
  75.         pteb (polar pte angb radt)
  76.         htrad (distance pte pts)
  77.                 ptsht (addz pts htrad)
  78.                 ptsbht (addz ptsb htrad)
  79.                 pteht (addz pte htrad)
  80.                 ptebht (addz pteb htrad)
  81.                 p1val (rnge 1 (fix (/ radt 2.7)))
  82.                  outang (angle pte pts)
  83.                  innang (angle pteb ptsb)
  84.                  ptemid (polar pte outang (/ htrad 2))
  85.                  ptebmid (polar pteb innang (/ (distance pteb ptsb) 2))
  86.                  midang (angle ptebmid ptemid)
  87.                  p4val (rnge 1 p1val)
  88.                  npte1 (polar pte angb p4val))
  89.                 (if (>= cnter 1) (setq npte1 npts1))
  90.                 (if (= cnter 0) (setq p2val (rnge 1 (fix (/ htrad 6)))))
  91.                 (if (= cnter 0) (setq p3val (rnge 1 p1val)))
  92.         (setq npte2 (polar npte1 (+ angb (dtr 90)) p2val)
  93.                 npte3 (polar npte2 midang p3val)
  94.                 npts1 (polar pts anga p4val)
  95.                 npts2 (polar npts1 (- anga (dtr 90)) p2val)
  96.                 npts3 (polar npts2 midang p3val)
  97.                 npte1ht (addz npte1 htrad)
  98.                 npte2ht (addz npte2 htrad)
  99.                 npte3ht (addz npte3 htrad)
  100.                 npts1ht (addz npts1 htrad)
  101.                 npts2ht (addz npts2 htrad)
  102.                 npts3ht (addz npts3 htrad))
  103.         (command "layer" "m" "line" "c" 5 "" "")
  104.         (command "3dface" pteb ptebht npte1ht npte1 "")
  105.         (command "3dface" npte1 npte1ht npte2ht npte2 "")
  106.         (command "3dface" npte2 npte2ht npte3ht npte3 "")
  107.         (command "3dface" npte3 npte3ht npts3ht npts3 "")
  108.         (command "3dface" npts3 npts3ht npts2ht npts2 "")
  109.         (command "3dface" npts2 npts2ht npts1ht npts1 "")
  110.         (command "3dface" npts1 npts1ht ptsbht ptsb "")
  111.         (command "3dface" ptsb ptsbht ptebht pteb "")
  112.         (command "3dface" ptebht npte1ht npte2ht npte3ht "")
  113.         (command "3dface" npts3ht npts2ht npts1ht ptsbht "")
  114.         (command "3dface" ptebht npte3ht npts3ht ptsbht "")
  115. (setq pteb ptsb
  116.         pte pts)
  117. )
  118. (defun prog ()
  119. (command "erase" (ssget "x") "")
  120. (command "redraw")
  121. (setq small (list 300 300)
  122.       large (list 1000 1000))
  123. (command "zoom" "w" small large)
  124. (command "layer" "m" "arcs" "c" 3 "" "")
  125. (setvar "cmdecho" 0)
  126. (setvar "pdmode" 35)
  127. (setvar "pdsize" 1)
  128. (setq pc (getpoint "\nPick a Point: ")
  129.         rd (getpoint pc "\nPick Radius and Start Angle: ")
  130.         anginc (getangle "\nEnter Angle in Degrees: ")
  131.       rad (distance pc rd)
  132.         ang (angle pc rd)
  133.         ps (polar pc ang rad)
  134.         pe (polar pc (+ ang anginc) rad)
  135.                         )
  136. (command "arc" "c" pc ps pe)
  137. (setq cntr (fix (/ 360 (atof (angtos anginc))))
  138.         cntb (- (/ cntr 2) 1)
  139.                 n "t")
  140. (while n
  141. (setq speb peb
  142.         ang (angle pe pc)
  143.         angrev (angle pc pe)
  144.         rad (* rad (sqrt 2))
  145.         pcb pc
  146.         pc (polar pe ang rad)
  147.         ps pe
  148.         pe (polar pc (+ angrev anginc) rad))
  149.         (command "layer" "m" "arcs" "c" 3 "" "")
  150.         (command "arc" "c" pc ps pe)
  151.         (if (> cntr cntb) (dvolp pcb))
  152.         (if (<= cntr cntb) (drawvolp pcb))
  153.         (command "layer" "m" "pnts" "c" 1 "" "")
  154.         (command "point" pe)
  155.                 (setq cntr (- cntr 1))
  156.                 (if (= cntr 0) (setq n nil))
  157.         (command "layer" "m" "arcs" "c" 3 "" "")
  158.         (command "arc" "c" pc ps pe)
  159.                 )
  160.                 (command "zoom" "e")
  161. )
  162. (defun reg ()
  163. (command "erase" (ssget "x") "")
  164. (setq small (list 300 300)
  165.       large (list 1000 1000))
  166. (command "zoom" "w" small large)
  167. (command "redraw")
  168. (command "layer" "m" "arcs" "c" 3 "" "")
  169. (setvar "cmdecho" 0)
  170. (setvar "pdmode" 35)
  171. (setvar "pdsize" 1)
  172. (setq pc (getpoint "\nPick a Point: ")
  173.         rd (getpoint pc "\nPick Radius and Start Angle: ")
  174.         anginc (getangle "\nEnter Angle in Degrees: ")
  175.       seed (getreal "\nEnter Seed: ")
  176.         pc1 pc
  177.         rad (distance pc rd)
  178.         ang (angle pc rd)
  179.         ps (polar pc ang rad)
  180.         pe (polar pc (+ ang anginc) rad))
  181.                 (command "pline")
  182.                 (setq cntr (fix (/ 360 (atof (angtos anginc))))
  183.                         cntb (/ cntr 2)
  184.                 n "t")
  185.         (while n
  186.                 (setq ang (angle pe pc)
  187.                         angrev (angle pc pe)
  188.                         rad (* rad (sqrt 2))
  189.                         pcb pc
  190.                         pc (polar pe ang rad)
  191.                         ps pe
  192.                         pe (polar pc (+ angrev anginc) rad))
  193.         (if (<= cntr cntb) (command ps "arc" "ce" pc pe))
  194.         (if (= cntr cntb) (setq ps1 ps))
  195.                 (setq cntr (- cntr 1))
  196.         (if (< cntr 0) (setq n nil))
  197.         )
  198.                 (command "")
  199.                 (command "line" ps1 pe "")
  200.                 (command "layer" "m" "pnts" "c" 1 "" "")
  201.                 (command "zoom" "e" "")
  202.                 (command "divide" ps (rnge 5 15))
  203.                         (setq pte pe
  204.                                 ss1 (ssget "x" (list (cons 0 "point")))
  205.                                 num (sslength ss1)
  206.                                 cnter 0)
  207.                         (repeat num
  208.                 (setq pts (cdr (assoc 10 (entget (ssname ss1 cnter)))))
  209.                                 (dvolreg pcb)
  210.                                 (setq cnter (1+ cnter))
  211.                                 )
  212.                                 (command "zoom" "e")
  213. )
  214. (defun c:try ()
  215.         (initget "Prog Reg")
  216.         (setq answer (getkword "\nWhat do you want <Prog/Reg>? "))
  217.         (cond
  218.                 ((= answer "Prog") (prog))
  219.                 ((= answer "Reg") (reg))
  220.         )
  221. )

应该是:
  1. (command "erase" (ssget "x") "")

2.
  1. (if (setq ss (ssget "x")) (command "erase" ss ""))

应为(2x):
  1. (1 + ...)
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 15:52:55 | 显示全部楼层
我会这样写主函数:
  1. (1+ ...)

这些子功能如下:
  1. (defun c:test ( / answer )
  2. (initget "Prog Reg")
  3. (or (setq answer (getkword "\nWhat do you want [Prog/Reg] <Prog> ? ")) (setq answer "Prog"))
  4. (cond
  5.         ((and (= answer "Prog") (= 'SUBR (type prog))) (princ "\nChoosed: Prog") (prog))
  6.         ((and (= answer "Reg") (= 'SUBR (type reg))) (princ "\nChoosed: Reg") (reg))
  7. )
  8. (princ)
  9. )

虽然我不确定全局参数出了什么问题,所以我没有涉及它们(只是在这些子函数中提供了额外的检查)。
还有(drawvolp)函数内部的这些行:
  1. (defun addz (pos inc / z)
  2. (and
  3.         pos (listp pos) (numberp inc)
  4.         (setq pos (list (car pos) (cadr pos) (+ inc (caddr pos))))
  5. )
  6. pos
  7. )
  8. (defun rnge (bot top)
  9. (and
  10.         (apply 'and (mapcar 'numberp (list bot top)))
  11.         (setq        r (+ bot (rand (- top bot))))
  12. )
  13. r
  14. )
  15. (defun rand (range / x z r)
  16. (and
  17.         (or (numberp seed) (setq seed 350))
  18.         (numberp range)
  19.         (setq x (1+ (* seed 2197.0)))
  20.         (setq z (fix (/ x 4096.0)))
  21.         (setq seed (fix (- x (* z 4096.0))))
  22.         (setq r (fix (1+ (abs (* (/ seed 4096.0) (- range 1.0))))))
  23. )
  24. r
  25. )
  26. (defun dvolp (pcn)
  27. (and
  28.         pcn (listp pcn) (apply 'and (mapcar 'numberp pcn))
  29.         (setq radb (distance ps pe))
  30.         (setq angb (angle ps pcn))
  31.         (setq psb (polar ps ang radb))
  32.         (setq peb (polar pe (* ang anginc) radb))
  33. )
  34. peb
  35. )

IMO,最好这样写:
  1. (command "layer" "m" "line" "c" 5 "" "")
  2. (command "3dface" psoa psoaht pscht psc "")
  3. (command "3dface" psc pscht pebht peb"")
  4. (command "3dface" peb pebht peoaht peoa "")
  5. (command "3dface" peoa peoaht penht pen "")
  6. (command "3dface" pen penht psnht psn "")
  7. (command "3dface" psn psnht psoaht psoa "")
  8. (command "3dface" pebht peoaht penht pebht "")
  9. (command "3dface" pscht psoaht psnht pscht "")
  10. (command "3dface" pebht penht psnht pscht "")

而且,当你这样写setq-s时:
  1. (command
  2. "_.LAYER" "m" "line" "c" 5 "" ""
  3. "_.3DFACE" "_non" psoa "_non" psoaht "_non" pscht "_non" psc ""
  4. "_.3DFACE" "_non" psc "_non" pscht "_non" pebht "_non" peb ""
  5. "_.3DFACE" "_non" peb "_non" pebht "_non" peoaht "_non" peoa ""
  6. "_.3DFACE" "_non" peoa "_non" peoaht "_non" penht "_non" pen ""
  7. "_.3DFACE" "_non" pen "_non" penht "_non" psnht "_non" psn ""
  8. "_.3DFACE" "_non" psn "_non" psnht "_non" psoaht "_non" psoa ""
  9. "_.3DFACE" "_non" pebht "_non" peoaht "_non" penht "_non" pebht ""
  10. "_.3DFACE" "_non" pscht "_non" psoaht "_non" psnht "_non" pscht ""
  11. "_.3DFACE" "_non" pebht "_non" penht "_non" psnht "_non" pscht ""
  12. )

这将只评估最后一个setq变量(正如塔瓦特教给我的),在您的情况下是:
  1. (setq pc (getpoint "\nPick a Point: ")
  2. rd (getpoint pc "\nPick Radius and Start Angle: ")
  3. anginc (getangle "\nEnter Angle in Degrees: ")
  4. seed (getreal "\nEnter Seed: ")
  5. ...
  6. )

因此,我建议采用经典方法,将用户输入提示与例程处理的rest变量分开:
  1. ... pe (polar pc (+ ang anginc) rad)

对不起,没有完全修订-通过子函数的全局变量和这些计算让我感到困惑
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 15:57:42 | 显示全部楼层
非常感谢,当我开始工作时,我会给你寄一份
回复

使用道具 举报

1

主题

7

帖子

6

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 16:01:05 | 显示全部楼层
您好,如果您给我发一个电子邮件地址,我会给您发一份我写的论文的副本,这样您就可以了解它过去的工作原理,非常感谢您今天上午的帮助,
 
厕所。cavendish@gmail.com
回复

使用道具 举报

1

主题

7

帖子

6

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 16:09:23 | 显示全部楼层
 
只需上传你在这里有什么(cadtutor)。我们不是唯一能帮助你的人。
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 16:17:10 | 显示全部楼层
论文以pdf格式附呈
回复

使用道具 举报

1

主题

7

帖子

6

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 16:24:53 | 显示全部楼层
论文的第二部分
回复

使用道具 举报

1

主题

7

帖子

6

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 16:28:54 | 显示全部楼层
您已经看到的代码
回复

使用道具 举报

1

主题

7

帖子

6

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 16:39:08 | 显示全部楼层
我成功了
 
回复

使用道具 举报

1

主题

7

帖子

6

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 16:43:19 | 显示全部楼层
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-14 21:08 , Processed in 0.424427 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表