帮助使用简单的Autolisp pr
你好我最近发现了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)成为可用变量
-错误:参数不足/太多。不知道该怎么做。。
以下是我迄今为止编写的代码,以澄清我的进展。
(defun c: ADefXYZ ()
;define the position of point A
(setq Ax (getreal "\specify first coordinate of point A: "))
(setq Ay (getreal "\specify second coordinate of point A: "))
(setq Az (getreal "\specify third coordinate of point A: "))
(defun c: DefPos (Ax Ay Az \ a1 a2)
(setq a1 (Ax Ay))
;get the coordinates of A'
(setq a2 (Ax Az))
;get the coordinates of A''
)
)
(defun c:d1a (\)
(command "insert" "ta1" a1 1 1 0)
;draw the A1 point
)
(defun c:d2a (\)
(command "insert" "ta2" a2 1 1 0)
;draw the A2 point
)
(defun c:lnp1 (\)
(command "xline" a1 b1 "")
;draw the line on the first plane
)
(defun c:lnp2 (\)
(command "xline" a2 b2 "")
;draw the line on the second plane
(defun *ERROR* (ErrStr)
(print ErrStr)
)
;end of defun
(princ)
非常感谢您的帮助!
干杯 欢迎加入
我会研究一种不同的方法:
(defun c:test (/ p1 p2 x1 y1 z1 x2 y2 z2)
(initget 1)
(setq p1 (getpoint "\n1st Point: "))
(setq x1 (nth 0 p1)
y1 (nth 1 p1)
z1 (nth 2 p1))
(initget 1)
(setq p2 (getpoint "\n2nd Point: "))
(setq x2 (nth 0 p2)
y2 (nth 1 p2)
z2 (nth 2 p2))
(setq a1 (list x1 y1 0)
a2 (list x1 y2 0))
)
虽然我不太明白你需要这个
- from the X and Z coord., i want to make the point A2 (X1, Y2=-Z)
我绝对建议为所有3个轴指定值。
您可能会在autolisp代码的任何片段周围使用代码标记。
希望这能让你开始-大卫 不是百分之百确定你在寻找什么或这个lisp的目的,但这应该让你开始。
(defun c:ADefXYZ (/ pointA pointB Ax Ay Az Bx By Bz)
(setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
(setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
;;(169.433 44.3076 0.0) This is a List of points ( X Y Z )
(setq Ax (nth 0 PointA)) ;;selects the 1st variable in the list pointA
(setq Ay (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
(setq Az (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
(setq Bx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
(setq By (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
(setq Bz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
(entmake (list (cons 0 "LINE") ;; Creates a Line
(cons 10 (list Ax Ay Az)) ;;1st point if you would not like to specify Az replace with 0.0
(cons 11 (list Bx By Bz)) ;;2nd point if you would not like to specify Az replace with 0.0
(cons 210 (list 0.0 0.0 1.0))))
)
这与David的lisp基本相同,只是解释了更多。 谢谢,我会调查的!
(y2=-z)是因为点的投影z坐标对应于应用于Y轴的z负值。
基本上,从3D空间中提取一个点,绘制到两个重叠的平面上,但分别显示由X轴分隔的俯视图和侧视图。
一些视觉辅助:
http://www.grad.hr/geomteh3d/Monge/02tocka/05.png popey3,
请阅读代码发布指南,并编辑您的帖子以包含代码标签。
我不想撒谎,这让我的头有点疼。这与我在绘图和3D建模方面所学的一切背道而驰。但这张照片带来了问题。如果你有一个-z或-y坐标,它会分别泄漏到y或z平面吗? 很抱歉,我刚刚收到了两封信,他已经来过这里了,但这封信还是让我挠头。
这是我对你要找的最好的猜测
;;different graphs
(defun c:ADefXYZ1 (/ pointA pointB Ax Ay Az Bx By Bz)
(setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
(setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
(setq Startpoint1 (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
(setq Startpoint2 (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
;;(169.433 44.3076 0.0) This is a List of points ( X Y Z )
(setq Xoff1 (nth 0 Startpoint1));;selects the 1st variable in the list
(setq Yoff1 (nth 1 Startpoint1));;selects the 2nd variable in the list
(setq Zoff1 (nth 2 Startpoint1));;selects the 3rd variable in the list
(setq Xoff2 (nth 0 Startpoint2));;selects the 1st variable in the list
(setq Yoff2 (nth 1 Startpoint2));;selects the 2nd variable in the list
(setq Zoff2 (nth 2 Startpoint2));;selects the 3rd variable in the list
(setq Ax (nth 0 PointA)) ;;selects the 1st variable in the list pointA
(setq Ay (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
(setq Az (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
(setq Bx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
(setq By (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
(setq Bz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
(setq A1 (list (+ Ax Xoff1) (+ Ay Yoff1) 0.0)) ;; finds coords based on startpoint offset
(setq A2 (list (+ Ax Xoff2) (+ (* -1 Az) Yoff2) 0.0));; finds coords based on startpoint offset
(setq B1 (list (+ Bx Xoff1) (+ By Yoff1) 0.0));; finds coords based on startpoint offset
(setq B2 (list (+ Bx Xoff2) (+ (* -1 Bz) Yoff2) 0.0));; finds coords based on startpoint offset
(entmake (list (cons 0 "LINE") ;; Creates a Line
(cons 10 A1) ;;1st point if you would not like to specify Az replace with 0.0
(cons 11 B1) ;;2nd point if you would not like to specify Bz replace with 0.0
(cons 210 (list 0.0 0.0 1.0))))
(entmake (list (cons 0 "LINE") ;; Creates a Line
(cons 10 A2) ;;1st point if you would not like to specify Az replace with 0.0
(cons 11 B2) ;;2nd point if you would not like to specify Bz replace with 0.0
(cons 210 (list 0.0 0.0 1.0))))
)
;;same graph
(defun c:ADefXYZ2 (/ pointA pointB Ax Ay Az Bx By Bz)
(setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
(setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
(setq Startpoint (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
;;(169.433 44.3076 0.0) This is a List of points ( X Y Z )
(setq Xoff (nth 0 Startpoint1));;selects the 1st variable in the list
(setq Yoff (nth 1 Startpoint1));;selects the 2nd variable in the list
(setq Zoff (nth 2 Startpoint1));;selects the 3rd variable in the list
(setq Ax (nth 0 PointA)) ;;selects the 1st variable in the list pointA
(setq Ay (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
(setq Az (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
(setq Bx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
(setq By (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
(setq Bz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
(setq A1 (list (+ Ax Xoff) (+ Ay Yoff) 0.0));; finds coords based on startpoint offset
(setq A2 (list (+ Ax Xoff) (+ (* -1 Az) Yoff) 0.0));; finds coords based on startpoint offset
(setq B1 (list (+ Bx Xoff) (+ By Yoff) 0.0));; finds coords based on startpoint offset
(setq B2 (list (+ Bx Xoff) (+ (* -1 Bz) Yoff) 0.0));; finds coords based on startpoint offset
(entmake (list (cons 0 "LINE") ;; Creates a Line
(cons 10 A1) ;;1st point if you would not like to specify Az replace with 0.0
(cons 11 B1) ;;2nd point if you would not like to specify Bz replace with 0.0
(cons 210 (list 0.0 0.0 1.0))))
(entmake (list (cons 0 "LINE") ;; Creates a Line
(cons 10 A2) ;;1st point if you would not like to specify Az replace with 0.0
(cons 11 B2) ;;2nd point if you would not like to specify Bz replace with 0.0
(cons 210 (list 0.0 0.0 1.0))))
) 嘿是的,在我的大学里,这是一个非常痛苦的话题。如果将4个以上的图形平面投影到图形上,情况会变得更糟。。。通常情况下,点和线总是在X轴上出血,这使得很难区分在哪个平面上是什么。大多数情况下,这是通过对图形进行颜色编码来应对的。
基本上,这是一个主题的化石遗迹,从那时起,一切都是手工绘制的,这就是你学会绘制几何正确的阴影的地方。完全多余的知识,但我将借此机会学习AutoLISP,因为要执行的任务仍然是非常基本的,主要是“放置点和绘制线”。
我会检查并尝试你建议的代码,然后再给你回复。谢谢你的帮助!
编辑:
好的,我已经查过了。整个绘画概念都很陌生,我甚至不想让你想太多,已经有足够多的人用头撞墙了:)
以下是一个视觉演示:
http://imageshack.us/photo/my-images/545/dgeometry.jpg/
Y轴和Z轴位于同一条线上,但指向相反方向。因此,当我在XZ平面上绘制时,我只取-Z值并将其应用于Y轴。 也许也是
(setq XYZ (getpoint "\nEnter X,Y,Z"))
(setq x (car xyz))
(setq y (cadr xyz))
(setq z (caddr xyz))
我明白了,这是清单上的第一、第二和第三项。有一个问题是,我怎样才能使第三个值为负?
页:
[1]
2