已知多边形求四角点
<font face="宋体" size="2">如图,已知左图求右图中四点~!图中虽然是矩形,但尽量可求平形四边形,而且不能用偏移求此点表</font> <p><strong><font color="#1111ee">严重鄙视楼上的行为,愿意帮忙就把代码贴出来,不帮忙就走开,耍什么噱头,真不知道你的水平到底有多高??!!</font></strong></p><p>;;方法通常有三种<br/>;;1.纯AutoLISP方法<br/>;;2.vlax方法<br/>;;3.vla方法<br/>;;下面以第三种为例<br/>;; (HS_get_Vertex (car (entsel)))<br/>(defun HS_get_Vertex (pl_ename / plst lst)<br/> (setq pl_ename (vlax-ename->vla-object pl_ename)<br/> plst (vlax-get pl_ename 'coordinates)<br/> )<br/> (repeat (/ (length plst) 2)<br/> (setq lst (append lst (list (list (car plst) (cadr plst))))<br/> plst (cddr plst)<br/> )<br/> )<br/> lst<br/>)</p> 先谢谢楼上的兄弟,但上面的程序不是我想要的,我要求的是4个红色点的点表,而这4个的是由矩形向内偏一个距离,而不是矩形的四个角点 先使用3楼的程序提取原矩形的角点坐标,再使用最简单的几何变换就行了。这种几何计算方法在网上一搜一大片 逛晕,说了等于没说..... <p>要别人全新写码给你吗?</p> <p>(defun GetVertexs (e / i v lst)<br/> (setq i -1)<br/> (while (setq v (vlax-curve-getpointatparam e (setq i (1+ i))))<br/> (setq lst (cons v lst))<br/> )<br/> (if (vlax-curve-isClosed e) (setq lst (cdr lst)))<br/> (reverse lst)<br/>)<br/>;;只对平行四边形有效,因为其他直段的多段线需要提供一个向量<br/>(defun PointsOffset (lst di)<br/> (mapcar '(lambda (x y z / a1 a2 a p)<br/> (setq a1 (angle y x)<br/> a2 (angle y z)<br/> a (abs (- a1 a2))<br/> )<br/> (if (>= a pi)<br/> (setq a (/ (- (* pi 2) a) 2))<br/> (setq a (/ a 2))<br/> )<br/> (setq p (mapcar '(lambda (x y) (/ (+ x y) 2))<br/> (polar y a1 1)<br/> (polar y a2 1)<br/> ))<br/> (polar y (angle y p) (/ di (sin a)))<br/> )<br/> (append (cdr lst) (list (car lst)))<br/> lst<br/> (append (list (last lst)) (reverse (cdr (reverse lst))))<br/> )<br/>)</p><p>;;测试<br/>(defun c:tt (/ e d ps os)<br/> (if (and (setq e (entsel))<br/> (setq d (getdist "\n指定偏移距离: ")))<br/> (progn<br/> (setq os (getvar "osmode")<br/> ps (GetVertexs (car e))<br/> ps (PointsOffset PS d)<br/> )<br/> (setvar "osmode" 0)<br/> (apply 'command (cons "_.pline" ps))<br/> (command "_close")<br/> (setvar "osmode" os)<br/> )<br/> )<br/> (princ)<br/>)<br/></p> http://bbs.mjtd.com/forum.php?mod=viewthread&tid=178602&highlight=%BD%C7%B5%E3&_dsign=c71b7f8f
页:
[1]