如何用lisp获取选择圆弧的起,始点,中点,圆心,角度
<p>如何用lisp获取选择圆弧的起,始点,中点,圆心,角度</p><p>请高手赐招, 谢谢!!</p><p><a href="mailto:shine_ks@sohu.com">shine_ks@sohu.com</a> 急切期待!!</p> 留个记号。以后会用到。谢谢 版主 收藏起来了
无私奉献,值得学习 高手在哪里? ;一个比较传统的求法
(defun c:test()
(if (setq ent (car (entsel "\n请选择圆弧:")))
(if (= (cdr (assoc 0 (setq db (entget ent)))) "ARC")
(progn
(setq pc (cdr (assoc 10 db)) ;圆心
r(cdr (assoc 40 db)) ;半径
a0 (cdr (assoc 50 db))
a1 (cdr (assoc 51 db))
ps (polar pc a0 r);起点
pe (polar pc a1 r);止点
pd (mapcar '* '(0.5 0.5) (mapcar '+ ps pe))
pm (polar pc (angle pc pd) r);中点
an (- a1 a0);圆心角
)
(if (< an 0) (setq an (+ an (* 2.0 pi))))
(princ (strcat "\n圆心=" (rtos (car pc) 2 3) "," (rtos (cadr pc) 2 3)))
(princ (strcat "\n起点=" (rtos (car ps) 2 3) "," (rtos (cadr ps) 2 3)))
(princ (strcat "\n止点=" (rtos (car pe) 2 3) "," (rtos (cadr pe) 2 3)))
(princ (strcat "\n中点=" (rtos (car pm) 2 3) "," (rtos (cadr pm) 2 3)))
(princ (strcat "\n圆心角=" (angtos an 1 6) ))
)
(alert "所选取的不是圆弧!")
)
)
)
<p>终于见到有人回贴了,非常感谢!!</p><p>不过我加载试用了,发现除了角度是正确的,获取的圆弧起,始点,中点,圆心坐标值都不对啊~~</p><p>还请高手赐招!!</p> 既然如此,把你的dwg文件发上来以验证程序的提取结果。如果角度是正确的,那就有一种可能,圆弧被平移或旋转过,起、止点,中点,圆心坐标值肯定与标注值不一致。 <p><span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;"><img height="446" src="file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image002.jpg" width="588" vshapes="_x0000_i1025" alt=""/></span></p><p><span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;"><span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;"><img height="387" src="file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image002.jpg" width="588" vshapes="_x0000_i1025" alt=""/></span></span></p> <p></p><p>我在坐标0点处画了任意一个圆弧, 获取值为:</p><p>圆心=-41.741,-451.203<br/>起点=-41.741,-553.958<br/>止点=61.014,-451.203<br/>中点=30.918,-523.862<br/>圆心角=90d0'0.00""\n圆心角=90d0'0.00\""</p><p>发现只有圆心角是对的,请赐教~~~谢谢!!</p> 因为在当前视口中定义了一个名为“未命名”的坐标系,其原点坐标为:X=-47.7047,Y=-451.2029,Z=0,这与世界坐标系的原点(X=0,Y=0,Z=0)不相重合,也就是说你那个坐标0点是由世界坐标原点X方向向左移动了47.7047,Y方向向下移动了451.2029,故此提取的坐标不能达到你预期的结果。关于“未命名”坐标系原点的数值,可在命令行中键入“ucsman”,并单击“详细信息(T)”就能看到,如下图:
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image002.jpg
相应的程序改为如下:
;一个比较传统的求法
(defun c:test()
(if (setq ent (car (entsel "\n请选择圆弧:")))
(if (= (cdr (assoc 0 (setq db (entget ent)))) "ARC")
(progn
(setq pc (cdr (assoc 10 db)) ;圆心
r(cdr (assoc 40 db)) ;半径
a0 (cdr (assoc 50 db))
a1 (cdr (assoc 51 db))
ps (polar pc a0 r);起点
pe (polar pc a1 r);止点
pd (mapcar '* '(0.5 0.5) (mapcar '+ ps pe))
pm (polar pc (angle pc pd) r);中点
an (- a1 a0);圆心角
)
(if (< an 0) (setq an (+ an (* 2.0 pi))))
(if (not (equal '(0 0 0) (setq org (getvar "ucsorg"))))
(setq pc (mapcar '- pc org)
ps (mapcar '- ps org)
pe (mapcar '- pe org)
pm (mapcar '- pm org)
)
)
(princ (strcat "\n圆心=" (rtos (car pc) 2 3) "," (rtos (cadr pc) 2 3)))
(princ (strcat "\n起点=" (rtos (car ps) 2 3) "," (rtos (cadr ps) 2 3)))
(princ (strcat "\n止点=" (rtos (car pe) 2 3) "," (rtos (cadr pe) 2 3)))
(princ (strcat "\n中点=" (rtos (car pm) 2 3) "," (rtos (cadr pm) 2 3)))
(princ (strcat "\n圆心角=" (angtos an 1 6) ))
)
(alert "所选取的不是圆弧!")
)
)
(princ)
)
<p>现在好了,非常感谢yshf!!</p><p>另外请教一下,获取圆弧周长的语法怎样写呀? </p><p>还有就是,我在做设计的时候经常会花许多时间做零件加工注解,</p><p>后来我写一个简单的程序,能够叫出注解图块,可以节省我很多时间.可是觉得不够好,</p><p>在修改注解内容的时候仍然需要输入,我希望能够双击注解图块可以出现对话框(附图),这样可以选择性修改,应该更方便些.</p><p>由于能力有限,所以在论坛上发贴求对话框的执行程序,可是一直无人回贴.</p><p>不知yshf可否帮忙,毕竟需要投入精力去写,所以我可以考虑付费.当然需要先谈好价钱的.呵呵~~</p><p>谢谢!!</p><p>我的QQ330646545</p> <p>附上我的小程序,很俗气的程序~~呵呵~~</p>
页:
[1]
2