求助:三点画矩形的LISP
<p> 由于工作需要,经常描图,是那种地面房屋的图(矩形,矩形的边与UCS的X、Y轴不平行),虽然cad2010提供的画矩形工具可以在选择第一点后,输入R进行旋转,但量大的时候,总觉得不方便,我的思路是:在屏幕上用鼠标选择矩形某条边上的两点角点,同时实现UCS的X轴自动调整与这条边(这两个角点连成的边)对齐,然后在屏幕上用鼠标选择第三个角点,自动画出矩形。也就是用三点画矩形。</p><p> 初学LISP,很感兴趣,但还是无能为力,恳请大侠帮忙了,跪谢。</p> 能用,非常感谢<font face="Verdana" color="#61b713"><b>liu_kunlun</b></font>,高手啊,我何时才能达到这个水平。。。。。感激之情无以言表。。。。。 liu_kunlun 发表于 2010-7-1 17:02
给你一个动态的
(defun c:tttt (/ os pt1 pt2 pt3 pt4 ag0 ag len ent ct in k) (setq os (getvar " ...
加载运行挺好用的,就是执行命令出现"瑙掔偣1:"是怎么回事?请指教一下,谢谢! 留个脚印,应该是有需要的! <font face="Verdana">(defun c:tttt (/ pt1 pt2 pt3 pt4 ag0 ag len)<br/> (while (and (setq pt1 (getpoint "角点1:"))<br/> (setq ag0 (getangle pt1 "角度:"))<br/> (setq pt3 (getpoint pt1 "对角点:"))<br/> (setq len (distance pt1 pt3) ag (angle pt1 pt3) )<br/> (setq pt2 (polar pt1 ag0 (* len (cos (- ag ag0)))))<br/> (setq pt4 (polar pt1 (+ (/ pi 2.) ag0) (* len (sin (- ag ag0)))))<br/> )<br/> (command "pline" pt1 pt2 pt3 pt4 "c" "")<br/> )<br/> (princ)<br/>)</font> <p>给你一个动态的</p>
<p><font face="Verdana">(defun c:tttt (/ os pt1 pt2 pt3 pt4 ag0 ag len ent ct in k)<br/> (setq os (getvar "osmode")) <br/> (while (and (setq pt1 (getpoint "\n角点1:"))<br/> (setq ag0 (getangle pt1 "角度:"))<br/> (progn (princ "对角点:") (setq ct t))<br/> (progn<br/> (setq ct t k t ent nil)<br/> (while ct<br/> (setq in (grread 1))<br/> (cond<br/> ( (= 5 (car in))<br/> (setq pt3 (cadr in))<br/> (setq len (distance pt1 pt3) ag (angle pt1 pt3) )<br/> (setq pt2 (polar pt1 ag0 (* len (cos (- ag ag0)))))<br/> (setq pt4 (polar pt1 (+ (/ pi 2.) ag0) (* len (sin (- ag ag0)))))<br/> (if ent (command "erase" ent ""))<br/> (setvar "osmode" 0)<br/> (command "pline" pt1 pt2 pt3 pt4 "c" )<br/> (setvar "osmode" os)<br/> (setq ent (entlast))<br/> )<br/> ( (= 3 (car in))<br/> (setq pt3 (cadr in))<br/> (setq len (distance pt1 pt3) ag (angle pt1 pt3) )<br/> (setq pt2 (polar pt1 ag0 (* len (cos (- ag ag0)))))<br/> (setq pt4 (polar pt1 (+ (/ pi 2.) ag0) (* len (sin (- ag ag0)))))<br/> (if ent (command "erase" ent ""))<br/> (setvar "osmode" 0)<br/> (command "pline" pt1 pt2 pt3 pt4 "c" )<br/> (setvar "osmode" os)<br/> (setq ent (entlast))<br/> (setq ct nil)<br/> )<br/> ( (equal '(11 0) in)<br/> (if ent (command "erase" ent ""))<br/> (setq ct nil k nil)<br/> )<br/> (t)<br/> ) <br/> )<br/> k<br/> ) <br/> ) <br/> <br/> )<br/> (setvar "osmode" os)<br/> (princ)<br/>)</font></p> 学习一下, 不错!<br/>
;; sdmt(三点描图) 2010年7月1日
(defun c:sdmt (/ p1 p2 rad mode motion code pt p3 p4 s2)
(while (and (setq p1 (getpoint "\n基点<退出>: "))
(setq p2 (getpoint p1 "\n方向点<退出>: "))
)
(princ "\n对角点: ")
(setq rad(angle p1 p2)
rad1 (+ rad (* pi 0.5))
mode t
)
(while mode
(setq MOTION (grread t 15 0)
CODE (car MOTION)
p3 (xyp-Grvecs-Osnap (cadr MOTION))
p2 (inters p1 p2 p3 (polar p3 rad1 10) nil)
p4 (inters p1 (polar p1 rad1 10) p3 (polar p3 rad 10) nil)
)
(redraw)
(cond ((= CODE 5) (XYP-GRVECS-PTLST (list p1 p2 p3 p4 p1) 3))
((= CODE 3)
(setq s2 (xyp-Entmake-lwPolyline (list p1 p2 p3 p4) t)
mode nil
)))))
(princ))
<p>2楼与6楼的方法都很好。</p>
<p>请问能够画成多点的就更理想。即在一条线的任意一边点击一下,输入距离,就画出一条垂直线。虽然在正交的模式下可以画,但有时图形不是水平方向的。</p>
<p>想学习修改一下,还是无能为力,恳求高手指教。</p>
<p>谢谢</p> <p>建议 先使用UCS 转换坐标系 再使用 plan 旋转屏幕</p> <p>使用坐标转换的工作量很大,像那种地面房屋的图,数量较多,不一定就是矩形,而是由多点组成的图形。</p>
<p>如果能左右两边点击,也就是指出哪个方向90度,再给一个距离,画出一个直角线,就快多了。不需要去旋转。</p>
<p>恳请大侠帮忙,谢谢!</p> <p><font face="Verdana">(defun c:hxjx ()<br/> (setvar "osmode" 0)<br/> (setvar "cmdecho" 0) <br/> (setq pa (getpoint "\n第一角点:")<br/> pb (getpoint "\n第二角点:")<br/> pc (getpoint "\n第三角点:")<br/> la (distance pa pb)<br/> lb (distance pb pc)<br/> lc (sqrt (+ (* la la) (* lb lb)))<br/> aa (angle pa pb) ;计算与x轴的夹角aa<br/> ab (atan (/ lb la))<br/> ac (+ aa (/ pi 2))<br/> pc (Polar Pa (+ aa ab) lc)<br/> pd (Polar Pa ac lb)<br/> )<br/> (command "pline" pa pb pc pd "c")<br/> (setvar "osmode" 47)</font></p>
<p><font face="Verdana">)<br/> (prompt "<<画斜矩形>>启动命令:hxjx")<br/> (princ)</font></p>
页:
[1]
2