我认为我不理解的部分是如何将三维点转换为二维点。。。。。
我能想到的唯一一件事是,当一个三维点被转换成一维的二维对象时,需要的是你们想要表达的东西。你可以画一条从(xy)到(xz)的线。假设你有一个点在(3.00 2.00 2.00)和一个图,其中正Y=Z,负Y=Y
Z
|
|
| P1 (3.00 2.00)
|
---------------X
|
| P2 (3.00 2.00)
|
|
Y
绘制一条线P1>P2,从2个点(0D)创建一条线(1D)。
但现在的问题是,如何在图上的两个给定点之间画一条线?然后我们将进入下一维度更高的0D(点)1D(线)2D(闭合形状)?
对于下一个示例,假设我们在(3.00 2.00 2.00)和(5.00 4.00 3.00)处有一个点。它会像下面这样吗?
Z
| P2
|
| P1
|
---------------X
|
| P4
| P3
|
Y
绘制线P1>P2>P3>P4>P1,创建闭合形状。
如果这是您想要使用的:
(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
(setq Startpoint (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
(setq Xoff (nth 0 Startpoint));;selects the 1st variable in the list
(setq Yoff (nth 1 Startpoint));;selects the 2nd variable in the list
(setq Zoff (nth 2 Startpoint));;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 p1 (list (+ Ax Xoff) (+ (* -1 Ay) Yoff)));; finds coords based on startpoint offset
(setq p2 (list (+ Ax Xoff) (+ Az Yoff)));; finds coords based on startpoint offset
(setq p3 (list (+ Bx Xoff) (+ Bz Yoff)));; finds coords based on startpoint offset
(setq p4 (list (+ Bx Xoff) (+ (* -1 By) Yoff)));; finds coords based on startpoint offset
(entmake (list (cons 0 "LINE") ;; Creates a Line
(cons 10 P1)
(cons 11 P2)
))
(entmake (list (cons 0 "LINE") ;; Creates a Line
(cons 10 P2)
(cons 11 P3)
))
(entmake (list (cons 0 "LINE") ;; Creates a Line
(cons 10 P3)
(cons 11 P4)
))
(entmake (list (cons 0 "LINE") ;; Creates a Line
(cons 10 P4)
(cons 11 P1)
))
)
***注意,这是基于当前UCS坐标的,如果UCS距离当前点10k单位,则x、y和z将偏离图表
这张图片是它将做什么的示例(不添加引线)
http://imageshack.us/a/img526/1900/adefxyz.png
我从不喜欢回忆
cadr caddr等我只使用N
(汽车xyz)=(第n个0 xyz)
(cadr xyz)=(第n个1 xyz)
(caddr xyz)=(第n个2 xyz)
我不记得是否有一个命令来做一个数字的倒数,但我只使用(*-1(nth2xyz)),基本上是-1*Z 我知道这让人困惑,但这是程序应该做的:
点P和T投影到两个平面上,因此它成为4个点。我们从来没有真正绘制三维空间,只是在坐标系中。
点P(x,y,z)分解为2个点,坐标为:
P1(x,y,0)
P2(x,-z,0)
另一点T(x1,y1,z1)也
T1(x1,y1,0)
T2(x1,-z1,0)
然后我可以画两行:
L1(P1,T1)
L2(P2,T2) 不确定Z是向上还是向下,所以只需删除一个你不想要的部分。
(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
(setq Startpoint (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
(setq Xoff (nth 0 Startpoint));;selects the 1st variable in the list
(setq Yoff (nth 1 Startpoint));;selects the 2nd variable in the list
(setq Zoff (nth 2 Startpoint));;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
;;if Z is down keep here
(setq p1 (list (+ Ax Xoff) (+ Ay Yoff)));; finds coords based on startpoint offset
(setq p2 (list (+ Ax Xoff) (+ (* -1 Az) Yoff)));; finds coords based on startpoint offset
(setq T1 (list (+ Bx Xoff) (+ By Yoff)));; finds coords based on startpoint offset
(setq T2 (list (+ Bx Xoff) (+ (* -1 Bz) Yoff)));; finds coords based on startpoint offset
;;if Z is down to here
;;if Z is up keep here
(setq p1 (list (+ Ax Xoff) (+ (* -1 Ay) Yoff)));; finds coords based on startpoint offset
(setq p2 (list (+ Ax Xoff) (+ Az Yoff)));; finds coords based on startpoint offset
(setq T1 (list (+ Bx Xoff) (+ (* -1 By) Yoff)));; finds coords based on startpoint offset
(setq T2 (list (+ Bx Xoff) (+ Bz Yoff)));; finds coords based on startpoint offset
;;if Z is up to here
(entmake (list (cons 0 "LINE") ;; Creates a Line
(cons 10 P1)
(cons 11 T1)
))
(entmake (list (cons 0 "LINE") ;; Creates a Line
(cons 10 P2)
(cons 11 T2)
))
)
为什么你第一次就不能这么说呢
这段代码的结果看起来与上面相同,只是没有连接坐标之间的垂直线 仅供参考:要对值求反:
_$ (setq x 10)
10
_$ (- x)
-10 真奇怪,不是吗<如果只向减号函数发送一个参数,则第一个参数有一个隐含的0。
至于如何更改列表中的项目,通常不会在lisp中进行更改。您只需要重新创建列表。在某些情况下,如关联列表(如DXF代码。数据对),您可以将subst与assoc一起使用。但使用subst基本上可以用一个项目替换整个列表中的新项目-例如。
(subst 2 1 '(1 2 3 1 2 3 1 2 3)) ;Returns (2 2 3 2 2 3 2 2 3)
您可能想看看ReplaceNth函数:http://www.theswamp.org/index.php?topic=41680.0
虽然对于这些要点列表,我不想麻烦。简单地做这样的事情并不太难:
;; Say originalPoint = (X Y Z)
(setq newPoint1 (list (car originalPoint) (cadr originalPoint) 0.0)) ; (X Y 0)
(setq newPoint2 (list (car originalPoint) (- (caddr originalPoint)) 0.0)) ; (X -Z 0) 谢谢大家的帮助!我根据帖子写下了我想要的东西。现在看起来是这样的:
(defun c:DrawAB ( / pointA pointB Axx Ayy Azz Byy Bzz)
(setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
(setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
(setq Axx (nth 0 PointA)) ;;selects the 1st variable in the list pointA
(setq Ayy (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
(setq Azz (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
(setq Bxx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
(setq Byy (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
(setq Bzz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
(setq P1 (list (* Axx -1) (* -1 Ayy))) ;;sets coords for p on plane (x-y)
(setq P2 (list (* Axx -1) Azz)) ;;sets coords for p on plane (x-z)
(setq T1 (list (* Bxx -1) (* -1 Byy))) ;;sets coords for T on plane (x-y)
(setq T2 (list (* Bxx -1) Bzz)) ;;sets coords for T on plane (x-z)
(command "line" P1 T1 "") ;;draws the line on plane (x-y)
(command "line" P2 T2 "") ;;draws the line on plane (x-z)
(command "insert" "tA1" P1 1 1 0) ;;inserts the mark for P on plane (x-y)
(command "insert" "tA2" P2 1 1 0) ;;inserts the mark for P on plane (x-z)
(command "insert" "tb1" T1 1 1 0) ;;inserts the mark for T on plane (x-y)
(command "insert" "tb2" T2 1 1 0) ;;inserts the mark for T on plane (x-z)
(princ)
)
我现在去掉了“从原点的偏移”部分,因为我正在尽可能地保持基本,现在将保持原始世界UCS上的所有内容,包括轴方向(否定值的原因)。一旦绘图变得更高级,我将进一步研究它,因此仍然感谢未来的提醒。
我想用“xline”替换“line”,但每次都会出错(块没有插入到正确的位置,线不会引用2个点,而只是一个坐标)。关于扭曲值的xline命令,有什么我应该知道的吗?
干杯 任何时候,只要使用(命令)调用并仅提供x和y值,就有可能出现不稳定的结果。它应该默认为当前sysvar“ELEVATION”值。但是,根据捕捉设置、ucs值等,没有真正好的方法可以预测准确的结果。您可以在点输入中添加“_non”,但这不是gaurntee-David 好的,我已经试着把Z输入为0.0,但是xline仍然给我schizo结果,而基线每次都能可靠地工作。因此,我决定将生成的行扩展到预定义的矩形边缘,而不是用作打印边距。到目前为止,我认为我已经将直线和矩形重命名为VLA对象,但现在有一个全新的VLA命令谱需要理解:P
有人能给我演示一下如何延长VLA线的模型吗?
此外,是否有方法输入X坐标并接收具有该坐标的线上的点?
现在我的代码是这样的:
(vl-load-com)
;;********************************************************************************************
(defun c:frame ( / ) ;;Draw the frame for the entire drawing
(setq corner1 (list -15.5 15 0))
(setq corner3 (list 5.5 -14 0))
(command "rectangle" corner1 corner3)
(setq F1 (entlast))
(setq FrameO(vlax-ename->vla-object F1))
)
;;********************************************************************************************
;;Define the coordinates of point A
(defun c:defA ( / )
(setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
(setq Axx (nth 0 PointA)) ;;selects the 1st variable in the list pointA
(setq Ayy (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
(setq Azz (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
(setq A1 (list (* Axx -1) (* -1 Ayy) 0.0)) ;;sets coords for p on plane (x-y)
(setq A2 (list (* Axx -1) Azz 0.0)) ;;sets coords for p on plane (x-z)
)
;;********************************************************************************************
;;Define the coordinates of point B
(defun c:defB ( / )
(setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
(setq Bxx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
(setq Byy (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
(setq Bzz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
(setq B1 (list (* Bxx -1) (* -1 Byy) 0.0)) ;;sets coords for T on plane (x-y)
(setq B2 (list (* Bxx -1) Bzz 0.0)) ;;sets coords for T on plane (x-z)
)
;;********************************************************************************************
;;Draw line with (X,Y) coordinates
(defun c:DrawP1 ( / pointA pointB Axx Ayy Azz Bxx Byy Bzz p1)
(entmake (list (cons 0 "LINE")(cons 10 A1)(cons 11 B1)))
(setq p1 (entlast))
(setq p1i(vlax-ename->vla-object p1))
)
;;********************************************************************************************
;;Draw line with (X,Z) coordinates
(defun c:DrawP2 ( / pointA pointB Axx Ayy Azz Bxx Byy Bzz p2)
;;
(entmake (list (cons 0 "LINE")(cons 10 A2)(cons 11 B2)))
(setq p2 (entlast))
(setq p2i(vlax-ename->vla-object p2))
(vla-lengthen p2 "dy" 5)
(vla-lengthen p2 "dy" -5)
)
;;********************************************************************************************
(defun c:insA ( / )
(command "insert" "tA1" A1 1 1 0) ;;inserts the mark for P on plane (x-y)
(command "insert" "tA2" A2 1 1 0) ;;inserts the mark for P on plane (x-z)
)
;;********************************************************************************************
(defun c:insB ( / )
(command "insert" "tb1" B1 1 1 0) ;;inserts the mark for T on plane (x-y)
(command "insert" "tb2" B2 1 1 0) ;;inserts the mark for T on plane (x-z)
)
;;********************************************************************************************
(princ)
您需要计算线的新起点和终点的坐标,然后更改VLA线对象的起点和终点属性。然而,这是不必要的,因为您可以首先创建一条长度和位置正确的线。
对于三维中的任意直线,可以计算直线向量(使用直线的起点和终点),然后使用直线方程计算具有给定X坐标(如果存在)的点的坐标;或者,可以计算线向量和Y-Z平面之间的交点,以及给定X坐标处的原点(或“高程”)。
e、 g.从这里使用我的线平面相交函数:
;; Line-Plane Intersection-Lee Mac
;; Returns the point of intersection of a line defined by
;; points p1,p2 and a plane defined by its origin and normal
(defun LM:IntersLinePlane ( p1 p2 org nm )
(setq org (trans org 0 nm)
p1(trans p10 nm)
p2(trans p20 nm)
)
(trans
(inters p1 p2
(list (car p1) (cadr p1) (caddr org))
(list (car p2) (cadr p2) (caddr org))
nil
)
nm 0
)
)
或者,对于平面中的二维线,可以使用inters函数(onseg参数设置为nil)来查找线向量和从平面中具有给定X坐标的点延伸的向量之间的交点,例如,对于X-Y平面中的线:
18或甚至有点三角:
关于它的价值,以下是我对基于您上一段代码的程序的看法:
不过,我还没有完整阅读这篇文章,所以很可能有更好的方法来实现您希望获得的结果。
请注意,上述内容不考虑UCS变化。
页:
1
[2]