乐筑天下

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

[编程交流] 查找圆柱体的中心线

[复制链接]

1

主题

7

帖子

20

银币

初来乍到

Rank: 1

铜币
9
发表于 2022-7-6 17:32:16 | 显示全部楼层 |阅读模式
使用AutoLisp,有人知道如何获得定义三维实体圆柱体中心线的两个三维点吗?圆柱体的方向和直径未知,可能已使用减法命令切割每一端以适合任何形状的另一个三维对象。
 
如果您知道如何在AutoCAD中手动执行此操作,即使它需要分解对象,我也可以将其自动化。
 
脚踏板
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 18:21:25 | 显示全部楼层
  1. ;; written by Hikolay Poleshuk
  2. ;; http://www.private.peterlink.ru/poleshchuk/cad/eng.html
  3. (defun 3dsolidinfo (/ ae w wl1 wl1e wl2 wle wltemp wstr)
  4. (setq ae (car (entsel "\nSelect a 3dSolid (cylinder):")))
  5. (setq wle (entget ae))
  6. (setq wl1e
  7. (mapcar 'cdr (vl-remove-if-not
  8. (function (lambda (w) (= 1 (car w))))
  9. wle)))
  10. (while wl1e
  11. (setq wstr (car wl1e))
  12. (setq wl1 (vl-string->list wstr))
  13. (setq wl2
  14. (mapcar
  15. '(lambda (w)
  16. (setq w (if (= w 32) 32 (boole 6 w 95)))
  17. (if (< w 32) (setq w (+ w 64)) w)
  18. )
  19. wl1
  20. )
  21. )
  22. (setq wltemp
  23. (append wltemp (list (vl-list->string wl2))))
  24. (setq wl1e (cdr wl1e))
  25. )
  26. wltemp
  27. )
  28. ; by *** 2004
  29. (defun strlist (strExp strDel / strLst)
  30. (while (setq pos (vl-string-position (ascii strDel) strExp))
  31.    (setq itm (substr strExp 1 pos))
  32.    (setq strLst (append strLst (list itm)))
  33.    (setq strExp (substr strExp (+ pos 2)))
  34. )
  35. (setq strLst (append strLst (list strExp)))
  36. )
  37. (defun C:test(/ axis_points info p1 p2)
  38. (setq info (3dsolidinfo))
  39. (setq axis_points
  40. (mapcar        (function
  41.   (lambda (n)
  42.     (cdddr (mapcar 'atof (strlist n " ")))))
  43. (mapcar        (function (lambda (s) (substr s 18)))
  44.         (vl-remove-if-not
  45.           (function (lambda (x) (wcmatch x "ellipse-curve $*")))
  46.           info))))
  47. (setq p1 (car axis_points)
  48.      p2 (cadr axis_points)
  49.      p1 (list (car p1)(cadr p1)(caddr p1))
  50.      p2 (list (car p2)(cadr p2)(caddr p2))
  51.      )
  52. (alert (strcat "Height of cylinder = " (rtos (distance p1 p2)) " drawing units"))
  53. (princ)
  54. )

 
请根据您的西装或
从那里抓取点P1和P2
 
~'J'~
回复

使用道具 举报

1

主题

7

帖子

20

银币

初来乍到

Rank: 1

铜币
9
发表于 2022-7-6 18:56:40 | 显示全部楼层
SPARKY77,
 
非常感谢,它几乎成功了!事实上,如果没有修改圆柱体端部,或者从中减去相同直径的圆柱体,则效果相当好。
 
下面是一个测试命令,将创建3个圆柱体来演示该条件。在它创建的红色圆柱体上使用test命令,您就会明白我的意思。
 
  1. (defun c:test2 ( / ss1)
  2. ;; Create 3 cylinders, one of which is shaped to fit the other two.  
  3. (command ".ucs" "W")
  4. ;; Create the two chord cylinders (that will be subtracted).
  5. (command ".cylinder" "0,0,0" 2.0 10.0)
  6. (setq ss1 (ssadd (entlast)))
  7. (command ".cylinder" "10,0,0" 1.0 10.0)
  8. (ssadd (entlast) ss1)
  9. (command ".vpoint" "1,-1,1")
  10. ;; Create the cylinders and fit the ends to the first two cylinders.
  11. (command ".ucs" "ZA" "10,0,2" "0,0,8")
  12. (command ".color" "r")
  13. (command ".cylinder" "0,0,0" 1.0 11.66190379)
  14. ;; Cope both ends to fit the chord cylinders.
  15. (command ".subtract" (entlast) "" ss1 "")
  16. ;; Recreate the two cylinders deleted by the subtract command.
  17. (command ".ucs" "W")
  18. (command ".color" "y")
  19. (command ".cylinder" "0,0,0" 2.0 10.0)
  20. (command ".cylinder" "10,0,0" 1.0 10.0)
  21. (command ".color" "w")
  22. (alert "Try the 'test' command on the red cylinder.  It reports the height of the cylinder is 0.0 units and p1 and p2 are identical.")
  23. ) ;_ defun c:test2
Footpeg
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 14:00 , Processed in 0.401295 second(s), 58 queries .

© 2020-2025 乐筑天下

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