乐筑天下

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

[编程交流] 帮助使用简单的Autolisp pr

[复制链接]

2

主题

10

帖子

8

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 07:08:09 | 显示全部楼层 |阅读模式
你好我最近发现了AutoLisp,正在掌握它的诀窍。首先,我想做一个简单的程序,它应该不会太难写,但我目前正在学习Lisp语法。有人能帮我写代码吗?
 
该程序旨在帮助学习画法几何,因此我希望该程序能做到以下几点:
 
定义点a
-我给它分配了3个独立的变量。这是点A的x,y,z坐标。
 
然后,我将这些三维坐标转换为二维空间,放到第一个和第二个“绘图平面”上
 
-从X坐标和Y坐标。,我想指出A1(X1,Y1)
-从X坐标和Z坐标。,我想指出A2(X1,Y2=-Z)
-然后在点A1和A2上插入预定义块
 
重复B点
 
在每个平面上绘制线AB
 
-在A1和B1之间画一条线
-在A2和B2之间画一条线
 
这几乎是我现在想要完成的全部,因为我昨天才开始。我目前需要以下方面的帮助:
-使坐标(x/y/z)成为可用变量
-错误:参数不足/太多。不知道该怎么做。。
 
以下是我迄今为止编写的代码,以澄清我的进展。
 
  1. (defun c: ADefXYZ ()
  2. ;define the position of point A
  3. (setq Ax (getreal "\specify first coordinate of point A: "))
  4. (setq Ay (getreal "\specify second coordinate of point A: "))
  5. (setq Az (getreal "\specify third coordinate of point A: "))
  6. (defun c: DefPos (Ax Ay Az \ a1 a2)
  7.                 (setq a1 (Ax Ay))
  8.                 ;get the coordinates of A'
  9.                 (setq a2 (Ax Az))
  10.                 ;get the coordinates of A''
  11. )
  12. )
  13. (defun c:d1a (\)
  14. (command "insert" "ta1" a1 1 1 0)
  15. ;draw the A1 point
  16. )
  17. (defun c:d2a (\)
  18. (command "insert" "ta2" a2 1 1 0)
  19. ;draw the A2 point
  20. )       
  21. (defun c:lnp1 (\)
  22. (command "xline" a1 b1 "")
  23. ;draw the line on the first plane
  24. )       
  25. (defun c:lnp2 (\)
  26. (command "xline" a2 b2 "")
  27. ;draw the line on the second plane
  28. (defun *ERROR* (ErrStr)
  29. (print ErrStr)
  30. )
  31. ;end of defun
  32. (princ)

 
非常感谢您的帮助!
干杯
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 07:12:12 | 显示全部楼层
欢迎加入
 
我会研究一种不同的方法:
 
  1. [b][color=BLACK]([/color][/b]defun c:test [b][color=FUCHSIA]([/color][/b]/ p1 p2 x1 y1 z1 x2 y2 z2[b][color=FUCHSIA])[/color][/b]
  2. [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b]
  3. [b][color=FUCHSIA]([/color][/b]setq p1 [b][color=NAVY]([/color][/b]getpoint [color=#2f4f4f]"\n1st Point:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
  4. [b][color=FUCHSIA]([/color][/b]setq x1 [b][color=NAVY]([/color][/b]nth 0 p1[b][color=NAVY])[/color][/b]
  5.        y1 [b][color=NAVY]([/color][/b]nth 1 p1[b][color=NAVY])[/color][/b]
  6.        z1 [b][color=NAVY]([/color][/b]nth 2 p1[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
  7. [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b]
  8. [b][color=FUCHSIA]([/color][/b]setq p2 [b][color=NAVY]([/color][/b]getpoint [color=#2f4f4f]"\n2nd Point:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
  9. [b][color=FUCHSIA]([/color][/b]setq x2 [b][color=NAVY]([/color][/b]nth 0 p2[b][color=NAVY])[/color][/b]
  10.        y2 [b][color=NAVY]([/color][/b]nth 1 p2[b][color=NAVY])[/color][/b]
  11.        z2 [b][color=NAVY]([/color][/b]nth 2 p2[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
  12. [b][color=FUCHSIA]([/color][/b]setq a1 [b][color=NAVY]([/color][/b]list x1 y1 0[b][color=NAVY])[/color][/b]
  13.        a2 [b][color=NAVY]([/color][/b]list x1 y2 0[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
  14. [b][color=BLACK])[/color][/b]

 
 
虽然我不太明白你需要这个
  1. - from the X and Z coord., i want to make the point A2 (X1, Y2=-Z)

 
我绝对建议为所有3个轴指定值。
 
您可能会在autolisp代码的任何片段周围使用代码标记。
 
希望这能让你开始-大卫
回复

使用道具 举报

13

主题

48

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 07:16:55 | 显示全部楼层
不是百分之百确定你在寻找什么或这个lisp的目的,但这应该让你开始。
 
  1. (defun c:ADefXYZ (/ pointA pointB Ax Ay Az Bx By Bz)
  2.       (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
  3. (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
  4. ;;(169.433 44.3076 0.0)   This is a List of points ( X Y Z )
  5. (setq Ax (nth 0 PointA)) ;;selects the 1st variable in the list pointA
  6. (setq Ay (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
  7. (setq Az (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
  8. (setq Bx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
  9. (setq By (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
  10. (setq Bz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
  11. (entmake (list (cons 0 "LINE") ;; Creates a Line
  12.          (cons 10 (list Ax Ay Az)) ;;1st point if you would not like to specify Az replace with 0.0
  13.          (cons 11 (list Bx By Bz)) ;;2nd point if you would not like to specify Az replace with 0.0
  14.          (cons 210 (list 0.0 0.0 1.0))))
  15. )

 
这与David的lisp基本相同,只是解释了更多。
回复

使用道具 举报

2

主题

10

帖子

8

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 07:18:11 | 显示全部楼层
谢谢,我会调查的!
 
(y2=-z)是因为点的投影z坐标对应于应用于Y轴的z负值。
 
基本上,从3D空间中提取一个点,绘制到两个重叠的平面上,但分别显示由X轴分隔的俯视图和侧视图。
一些视觉辅助:
http://www.grad.hr/geomteh3d/Monge/02tocka/05.png
回复

使用道具 举报

4

主题

2143

帖子

2197

银币

限制会员

铜币
-24
发表于 2022-7-6 07:24:05 | 显示全部楼层
popey3,
 
请阅读代码发布指南,并编辑您的帖子以包含代码标签。
回复

使用道具 举报

13

主题

48

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 07:25:19 | 显示全部楼层
 
我不想撒谎,这让我的头有点疼。这与我在绘图和3D建模方面所学的一切背道而驰。但这张照片带来了问题。如果你有一个-z或-y坐标,它会分别泄漏到y或z平面吗?
回复

使用道具 举报

13

主题

48

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 07:28:21 | 显示全部楼层
很抱歉,我刚刚收到了两封信,他已经来过这里了,但这封信还是让我挠头。
 
这是我对你要找的最好的猜测
 
  1. ;;different graphs
  2. (defun c:ADefXYZ1 (/ pointA pointB Ax Ay Az Bx By Bz)
  3. (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
  4. (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
  5. (setq Startpoint1 (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
  6. (setq Startpoint2 (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
  7. ;;(169.433 44.3076 0.0)   This is a List of points ( X Y Z )
  8. (setq Xoff1 (nth 0 Startpoint1));;selects the 1st variable in the list
  9. (setq Yoff1 (nth 1 Startpoint1));;selects the 2nd variable in the list
  10. (setq Zoff1 (nth 2 Startpoint1));;selects the 3rd variable in the list
  11. (setq Xoff2 (nth 0 Startpoint2));;selects the 1st variable in the list
  12. (setq Yoff2 (nth 1 Startpoint2));;selects the 2nd variable in the list
  13. (setq Zoff2 (nth 2 Startpoint2));;selects the 3rd variable in the list
  14. (setq Ax (nth 0 PointA)) ;;selects the 1st variable in the list pointA
  15. (setq Ay (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
  16. (setq Az (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
  17. (setq Bx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
  18. (setq By (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
  19. (setq Bz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
  20. (setq A1 (list (+ Ax Xoff1) (+ Ay Yoff1) 0.0)) ;; finds coords based on startpoint offset
  21. (setq A2 (list (+ Ax Xoff2) (+ (* -1 Az) Yoff2) 0.0));; finds coords based on startpoint offset
  22. (setq B1 (list (+ Bx Xoff1) (+ By Yoff1) 0.0));; finds coords based on startpoint offset
  23. (setq B2 (list (+ Bx Xoff2) (+ (* -1 Bz) Yoff2) 0.0));; finds coords based on startpoint offset
  24. (entmake (list (cons 0 "LINE") ;; Creates a Line
  25.          (cons 10 A1) ;;1st point if you would not like to specify Az replace with 0.0
  26.          (cons 11 B1) ;;2nd point if you would not like to specify Bz replace with 0.0
  27.          (cons 210 (list 0.0 0.0 1.0))))
  28. (entmake (list (cons 0 "LINE") ;; Creates a Line
  29.          (cons 10 A2) ;;1st point if you would not like to specify Az replace with 0.0
  30.          (cons 11 B2) ;;2nd point if you would not like to specify Bz replace with 0.0
  31.          (cons 210 (list 0.0 0.0 1.0))))
  32. )
  33. ;;same graph
  34. (defun c:ADefXYZ2 (/ pointA pointB Ax Ay Az Bx By Bz)
  35. (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
  36. (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
  37. (setq Startpoint (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
  38. ;;(169.433 44.3076 0.0)   This is a List of points ( X Y Z )
  39. (setq Xoff (nth 0 Startpoint1));;selects the 1st variable in the list
  40. (setq Yoff (nth 1 Startpoint1));;selects the 2nd variable in the list
  41. (setq Zoff (nth 2 Startpoint1));;selects the 3rd variable in the list
  42. (setq Ax (nth 0 PointA)) ;;selects the 1st variable in the list pointA
  43. (setq Ay (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
  44. (setq Az (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
  45. (setq Bx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
  46. (setq By (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
  47. (setq Bz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
  48. (setq A1 (list (+ Ax Xoff) (+ Ay Yoff) 0.0));; finds coords based on startpoint offset
  49. (setq A2 (list (+ Ax Xoff) (+ (* -1 Az) Yoff) 0.0));; finds coords based on startpoint offset
  50. (setq B1 (list (+ Bx Xoff) (+ By Yoff) 0.0));; finds coords based on startpoint offset
  51. (setq B2 (list (+ Bx Xoff) (+ (* -1 Bz) Yoff) 0.0));; finds coords based on startpoint offset
  52. (entmake (list (cons 0 "LINE") ;; Creates a Line
  53.          (cons 10 A1) ;;1st point if you would not like to specify Az replace with 0.0
  54.          (cons 11 B1) ;;2nd point if you would not like to specify Bz replace with 0.0
  55.          (cons 210 (list 0.0 0.0 1.0))))
  56. (entmake (list (cons 0 "LINE") ;; Creates a Line
  57.          (cons 10 A2) ;;1st point if you would not like to specify Az replace with 0.0
  58.          (cons 11 B2) ;;2nd point if you would not like to specify Bz replace with 0.0
  59.          (cons 210 (list 0.0 0.0 1.0))))
  60. )
回复

使用道具 举报

2

主题

10

帖子

8

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 07:30:29 | 显示全部楼层
嘿是的,在我的大学里,这是一个非常痛苦的话题。如果将4个以上的图形平面投影到图形上,情况会变得更糟。。。通常情况下,点和线总是在X轴上出血,这使得很难区分在哪个平面上是什么。大多数情况下,这是通过对图形进行颜色编码来应对的。
 
基本上,这是一个主题的化石遗迹,从那时起,一切都是手工绘制的,这就是你学会绘制几何正确的阴影的地方。完全多余的知识,但我将借此机会学习AutoLISP,因为要执行的任务仍然是非常基本的,主要是“放置点和绘制线”。
 
我会检查并尝试你建议的代码,然后再给你回复。谢谢你的帮助!
 
编辑:
好的,我已经查过了。整个绘画概念都很陌生,我甚至不想让你想太多,已经有足够多的人用头撞墙了:)
以下是一个视觉演示:
http://imageshack.us/photo/my-images/545/dgeometry.jpg/
Y轴和Z轴位于同一条线上,但指向相反方向。因此,当我在XZ平面上绘制时,我只取-Z值并将其应用于Y轴。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 07:33:55 | 显示全部楼层
也许也是
 
  1. (setq XYZ (getpoint "\nEnter X,Y,Z"))
  2. (setq x (car xyz))
  3. (setq y (cadr xyz))
  4. (setq z (caddr xyz))
回复

使用道具 举报

2

主题

10

帖子

8

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 07:39:30 | 显示全部楼层
 
我明白了,这是清单上的第一、第二和第三项。有一个问题是,我怎样才能使第三个值为负?
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 15:24 , Processed in 0.779592 second(s), 72 queries .

© 2020-2025 乐筑天下

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